Sponsored Content
Full Discussion: Cron won't restart rsyslog
Top Forums Shell Programming and Scripting Cron won't restart rsyslog Post 302757255 by sstrahm001 on Thursday 17th of January 2013 09:20:47 AM
Old 01-17-2013
Cron won't restart rsyslog

Howdy,

I am nearly tearing my hair out as Cron isn't running a script that should work.

I am interning for a company. Their rsyslog keeps track of traffic that gets past a firewall. It creates two files called pix.log and pix2.log. Every time something happens with the firewall, it adds to these files.

The files are getting a bit big after a while, so my employer wants a script to move the files everyday to another location, rename them with the date, restart rsyslog, and start anew.

I have never scripted anything in my life. So, after a few days of researching, I created this shell script.

This is the script currently
Code:
#!/bin/script

#stop rsyslog
sudo service rsyslog stop

#copy and move pix.log
cp /var/log/pix.log /run/media/root/2.1/2.1/"`date +%m-%d-%Y'_pix.log
mv /var/log/pix.log /run/media/root/2.253/2.1/"`date +%m-%d-%Y'_pix.log

#copy and move pix2.log
cp /var/log/pix2.log /run/media/root/2.1/2.253/"`date +%m-%d-%Y'_pix2.log
mv /var/log/pix2.log /run/media/root/2.253/2.253/"`date +%m-%d-%Y'_pix2.log

#start rsyslog
sudo service rsyslog start

If I run the script myself (as root user), it works great. It moves the files to where they need to be, renames them with the date, and rsyslog restarts. However, when I tell cron to do it, its wonky.

I set up cronttab as this (also as root user):
Code:
59 23 * * * /usr/sbin/pixmove.sh

I know cron is running the file because it says so in the cron.log. It moves and renames the files with the correct date, but pix.log and pix2.log is not created. I have to manually put in "service rsyslog restart" into terminal for them to be created again. When Cron runs the script, the script does not stop or start rsyslog. I tried deleting the first and last command and ending the script with "sudo service rsyslog restart". It works when I run the script, but not when Cron runs it.

I also tried creating a script just to run "service rsyslog restart" and have Cron run it one minute after the first script ran. When I execute it, it works. When Cron runs it, it does not.

I am the root user when doing all this. I tried moving the script to where the rsyslog file is located (maybe cron cant find it?) but no luck.

So my question is, how do I get cron to stop/start/restart rsyslog by itself? To my understanding, Cron is used to autoexecute programs, so I don't know why the script would run any differently (unless cron is not acting as the root user)

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.


Edit: Sorry about that mod. Its pretty much pasted everywhere to do so. Won't happen again

Last edited by sstrahm001; 01-17-2013 at 11:15 AM.. Reason: whoops
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Simple cron job won't work

I have a script in a directory -say users/me/test/ It looks like this: # "bkup" - copies specified files to the user's ~/Backup # directory after checking for name conflicts. a=$(date +%T) cp $1 ~/test/Backup/$1.$a It copies file.txt from current directory and timestamps the name of it of... (4 Replies)
Discussion started by: coregan
4 Replies

2. UNIX for Dummies Questions & Answers

Cron won't run properly

I am new to unix, and this is my 1st post on this board. Looking for some advice about a cron job in my server. I am running a cron task that references a script which runs several other scripts and compiles them into a report and emails it to me. If I run the script manually, I will... (2 Replies)
Discussion started by: Steeler_fan
2 Replies

3. UNIX for Dummies Questions & Answers

How to restart a CRON

If my cron has recieved a SIGTERM. How do I restart the cron? (7 Replies)
Discussion started by: ddrivera
7 Replies

4. Linux

How do cron restart on unix Tru64?

hi all, How do cron restart on unix Tru64? because don't run my cron jobs. few days age it's running fine. I did below steps: 1. cd /usr/sbin 2. cron stop response: "! Cron is already running. Exiting... Tue Nov 27 14:38:00 2007" 3. cron start response: "! Cron is already running.... (2 Replies)
Discussion started by: Tlg13team
2 Replies

5. Linux

How do cron restart on unix Tru64?

hi all, How do cron restart on unix Tru64? because don't run my cron jobs. few days age it's running fine. I did below steps: 1. cd /usr/sbin 2. cron stop responce: "! Cron is already running. Exiting... Tue Nov 27 14:38:00 2007" 3. cron start responce: "! Cron is already running.... (2 Replies)
Discussion started by: Tlg13team
2 Replies

6. UNIX for Dummies Questions & Answers

How to restart CRON file?

Hi How can I restart the CRON manually? Thanks (1 Reply)
Discussion started by: biot
1 Replies

7. AIX

won't mount /usr...won't boot fully

Hello: NOOB here. I attempted to use smit mkcd. Failed on first attempt, not enough space. 2nd attempt tried to place iso on /usr, not enough space there. Cleanup ran for about 5 minutes after aborting. Now AIX won't boot. LCD display on 7029-6E3 says: 0517 MOUNT /USR. Attempted to boot from CD... (11 Replies)
Discussion started by: bbird
11 Replies

8. Shell Programming and Scripting

RSYSLOG reports

I want to create reports using rsyslog in linux,Can someone help me out here ? Report Format must be "Hostname" "Username" "Hostname logged from" "Date" "Time" Regards, Ahmed. ---------- Post updated at 05:24 PM ---------- Previous update was at 05:24 PM ---------- Linux,Shell Script (10 Replies)
Discussion started by: ahmed.vaghar
10 Replies

9. UNIX for Beginners Questions & Answers

Bash script won't run because hardware won't produce display

Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
Discussion started by: yelirt5
3 Replies
All times are GMT -4. The time now is 02:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy