Cron won't restart rsyslog


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron won't restart rsyslog
# 1  
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
# 2  
Old 01-17-2013
Try logging all your actions in a file and test with at utility.

This will give you a idea about what is happening when your script is running automatically.
# 3  
Old 01-17-2013
It says I need a tty to run sudo.
# 4  
Old 01-17-2013
So now this is evident!

The script fails when u try to use sudo and executes the next set of commands. From your above script, successful commands are only copying and moving. You have to re-construct your sscript Smilie
# 5  
Old 01-17-2013
Ok, so the copy and move part is good but not the sudo part.

So what would be the command to ether shut off and then turn on rsyslog or to just restart rsyslog? The rsyslog need to be restarted (or turned back on) to create and continue writing to pix.log and pix2.log
# 6  
Old 01-17-2013
Question:
Since you are root ( if its root crontab...), why are you using sudo?
cron is quite dumb you know... Did you try the script in interactive mode (from your connecting/login shell...) what happens? If it works then you have an environment issue...
The start would be to give the absolute paths to executables or to set environment variables so cron has all it need to work...
# 7  
Old 01-17-2013
I was using sudo as I'm pretty much a newbie when it comes to anything linux (I created this post before seeing there was a newbie section). I read somewhere its what I should do so I did it.

Ill look up the absolute path to rsyslog and see if I can start/stop/restart it that way.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question