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