How to make cronjob output to different files everyday


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to make cronjob output to different files everyday
# 1  
Old 10-25-2009
How to make cronjob output to different files everyday

Hello,

I have a cronjob that i am currently running which is as follows:
php /home/****/cronjob.php --debug 2>&1 >> /home/cronjoboutput.txt

That, as you may know, logs the output to a file called cronjoboutput.txt in the home directory.

I want that cronjob to output to a different file everyday so if today is the 25th (25-10-2009) then it will output to "/home/ilog/25-10-2009.log". And if the date changes to the 26th then it starts logging to "/home/ilog/26-10-2009.log".

Can someone please write up a command that does this for me?

Thanks!
# 2  
Old 10-25-2009
Hello!

Per forum rules, and the benefit of all users, please search the forums before posting a question.

You can easily search the forums using our internal Google search engine or our advanced internal search engine. You can also search our huge UNIX and Linux database by user generated tags or search the database for unanswered questions and provide an answer.

Thank you.

The UNIX and Linux Forums

---------- Post updated at 22:38 ---------- Previous update was at 22:37 ----------

Searching for "date in filename" gives (at least) this, this, this, and that.
# 3  
Old 10-25-2009
set the output file to

Code:
>/home/ilog/`date +"%m-%d-%Y"`.txt

# 4  
Old 10-25-2009
Code:
>> /home/ilog/$(/bin/date +%d-%m-%Y).log

# 5  
Old 10-25-2009
Hey im sorry but i did search but i didnt find anything that i thought would be helpful.. I am very new to this.

---------- Post updated at 06:40 PM ---------- Previous update was at 05:56 PM ----------

Hello.

From the /var/log/cron i see that it says this now:
Oct 25 23:35:01 server crond[13367]: (root) CMD (php /home/admin/clients.hostwoot.com/cron/cronjob.php --debug 2>&1 >> /ipanel_log/$(/bin/date +)

It looks like the command i put there is not working because i dont see any files there...

The cron:
php /home/***/cronjob.php --debug 2>&1 >> /ipanel_log/$(/bin/date +%d-%m-%Y).log
# 6  
Old 10-26-2009
You need to escape percentage signs \% in crontab lines because they have a meaning to cron (see the manual for your crontab).
Whether either of the suggested solutions will then work depends on what shell your operating system uses for cron jobs. In general it is better to write a controlling script containing a shebang and any local environment settings and then call that script from cron.


Also, there are 6 parameters to a crontab line. Your example line does not look like a normal crontab line.
# 7  
Old 10-26-2009
Thanks for all the help. I am extremely grateful for all the help you have provided.

I have got it working perfectly now Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Top Command Output is not coming via Cronjob

Dear All, I created a small script to get the CPU, GIS usage etc automatically. However when i run this script manually its working , but when i run through cronjob i am not getting any output. Can anyone please help me on this. I am using SuseLinux. Thank you in advance. #!/bin/sh {... (2 Replies)
Discussion started by: Nitin Kapoor
2 Replies

2. UNIX for Dummies Questions & Answers

Cronjob output to file AND to email (as attachment)

I have a shell script that runs on our webserver logs, and grabs various useful data and then outputs this data to a .csv file. What I want to do now is schedule a cronjob to run this script for me each week at a designated time, AND email the .csv file that is created as an attachment to... (1 Reply)
Discussion started by: xdawg
1 Replies

3. Ubuntu

Top output to textfile not working in cronjob

Hello, If i run the following script from the cmdline it works just fine however if i run it via root cronjob it doesn't write to the file at all. It is chmod 777 now so shouldnt be any right issues. Shellscript looks like this: /usr/bin/top -b -n 1 -u nagios >> /var/log/test.log Cronjob... (7 Replies)
Discussion started by: heady89
7 Replies

4. UNIX for Dummies Questions & Answers

Make-output

hi dear i need help about following command that i require for installing szip software ./configure --prefix=/usr/local make all install >& make-output my question is what >& make-output command do? does it make folder called make-output?:confused: thanks in advance fereshte Use... (2 Replies)
Discussion started by: komijani
2 Replies

5. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

6. Shell Programming and Scripting

Cronjob for recognizing changes and/or new files in specific directory

Hey Guys, is there a way to create a cronjob to watch over all changes in a specific directory, for example /home/user and send them, if there are any changes, to a server:confused: Thanks Sebi0815 (4 Replies)
Discussion started by: Sebi0815
4 Replies

7. Shell Programming and Scripting

Capturing and sending of vmstat output everyday

I need to capture the vmstat output of a server every 5 minutes, in a text filename with the name in the format vmoutput. yesterday's date.txt. I need to get the vmstat o/p for the whole day with 5 minutes interval and send it (preferably ftp) to my local desktop folder. eg: vmstat 300... (1 Reply)
Discussion started by: yuvanash
1 Replies

8. Shell Programming and Scripting

Cronjob - Redirect mail output to file, LINES & COLUMNS

I currently have an expect script that issues the 'mail' command and sends an 'x' when it receives the & prompt from mail to quit. The expect script is able to do stty rows 100 columns 200 < $spawn_out(slave,name) to set up the number of columns and rows. I would like to get rid of the expect... (0 Replies)
Discussion started by: jharvey
0 Replies

9. Shell Programming and Scripting

how to make a line BLINKING in output and also how to increase font size in output

how to make a line BLINKING in output and also how to increase font size in output suppose in run a.sh script inside echo "hello world " i want that this should blink in the output and also the font size of hello world should be big .. could you please help me out in this (3 Replies)
Discussion started by: mail2sant
3 Replies
Login or Register to Ask a Question