Crontab runs a script on UNIX

Have a simple script to run the top comman nand to save the result in a txt file. He will start the cycle 3 times a day with a 1-hour interval. After that, the email will be sent using the contents of the text file as the body of the email and delete the text file so that a new text file appears the next day.

Problem

  • To automate the process, I created a cronjob to start at 8:30 pm, which will run the script, and my script will continue to run for 4 hours, and the result of the command will be added to the text file and finally sent by mail. CRON is →0 10 * * * /tmp/ssh-abc/KKK/Report.sh

    /tmp/ssh-abc/KKK/Report.sh: line 34: ReportProd.txt: Permission denied

The code

To create a txt file

{
//Some Logic
} >> ReportProd.txt   //Running script manually works great and generate txt!!

Delete the file after distribution.

find /tmp/ssh-abc/KKK/*.txt -type f -delete   //This works fine manually,file is getting generated and deleted also.

/tmp/ssh-abc/KKK/Report.sh: 39: ReportProd.txt:

, ? , .   0755 cron - . Tried giving cd and path and then the command in crontab but seems not working

  • , crontab , .

: #!/bin/ bash "whereis sh" sh:/bin/sh/usr/share/man/man1/sh.1.gz/USR///man1p/sh.1p.gz

+4
3

script , cd , ReportProd.txt. script , , cron .
script /tmp/ssh-abc/KKK/Report.sh , /tmp/ssh-abc/KKK.

, . :

{
# Output generated here
} >> /full/path/to/output/ReportProd.txt
+1

0 10 * * * sudo sh/tmp/ssh-abc/KKK/Report.sh

, , . Cron root crontab -e

0

/bin/sh /tmp/ssh-abc/KKK/Report.sh

do

chmod 755 /tmp/ssh-abc/KKK/Report.sh

script .

-1

Source: https://habr.com/ru/post/1584062/


All Articles