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