Dennis Schwarts
Dennis Schwarts

Reputation: 45

how to create multi tasking cron job?

I am trying to create a cron job, that create a new file every 06:00 in the morning, giving him a full 644 permission (write&read), and after copy it to a different location.

Do i need to create 2 different cron jobs? one for creating and one for copying? right now i done the copy part (i create the files manually):

*/2 * * * * cp -rf /var/www/html/emaillist.txt /home/uview/emaillistforwatch/ 

Upvotes: 0

Views: 867

Answers (2)

Elham_Jahani
Elham_Jahani

Reputation: 367

you can also use both of script and '&&'

the '&&' force your second command that be run after (only after) the first command fully implemented

for example :

touch script.sh
chown a+x script.sh
vim script.sh
   #!/bin/bash
   touch /YOUR_FILE_ADDRESS/file.txt && chown 644 /YOUR_FILE_ADDRESS/file.txt && cp /YOUR_FILE_ADDRESS/file.txt /DESTINATION_ADDRESS echo "`date`  done" >> result.log

and configure crontab :

crontab -e
   0 6 * * *         /SCRIPT_ADDRESS/script.sh

Upvotes: 0

Kotler
Kotler

Reputation: 151

I think you can use option "&&", because with option you can run multi tasking in cronjob.

Ex:

*/2 * * * * mkdir /var/www/html/test && cp -rf /var/www/html/emaillist.txt /var/www/html/test

Or You can create file script and add multi tasking in scirpt. After you can add file scritp in cron run is ok.

Ex: File test.sh:

#!/bin/bash
dir=$(pwd)
mkdir test
cp test.txt test
echo "done"

In cron:

*/2 * * * * bash test.sh

Upvotes: 1

Related Questions