Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My script is located in /opt/restart-hlasic.sh

restart-hlasic.sh contains:

#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/
SERVER="XXX"
TOEMAIL="XXX@XXX"
FROMEMAIL="XXX@XXX"
# Line divider
DL="~~~~~~~~~~~"
# Put the email together
BODY="${DL}
`date`
${DL}
Server byl restartovan
"

echo "${BODY}" | perl -e '($_ = join "",<>) =~ s/(\t)/     /g; print;' | sendEmail -f "${FROMEMAIL}" -u "${SERVER} St$

If I run script manually, mail is sent to me, but when I restart server, crontab doesn't run this script.

crontab -e

@reboot /opt/restart-hlasic.sh

I think that this is correct, or am I wrong? Thank you for help.

share|improve this question

migrated from stackoverflow.com Apr 11 '13 at 0:17

This question came from our site for professional and enthusiast programmers.

1  
The expand command is probably a better way to expand tabs; your perl command replaces each tab with a fixed number if spaces, which is not usually what you want. Where is the sendEmail command? –  Keith Thompson Apr 10 '13 at 19:42
    
#!/bin/bash is wrong, it will be executed by sh, but I don't think that's your problem. –  tripleee Apr 10 '13 at 19:47
1  
You say the script is kontrola, but the cron job runs restart-hlasic. Are you confused, or are you omitting something? –  tripleee Apr 10 '13 at 19:49
    
@tripleee: The command in the crontab is executed by sh, but the command is /opt/restart-hlasic.sh which has #!/bin/bash, so the command executed by sh is effectively /bin/bash /opt/restart-hlasic.sh. –  Keith Thompson Apr 10 '13 at 23:07
add comment

1 Answer

up vote 0 down vote accepted

Please post how the script start is configured with cron.

I guess you try to run it when the server is (re) started. Maybe better solution would be to put the script into /etc/rc.d/rcX.d/S99"whatever" to execute it at system start. Using cron sounds... cumbersome.

share|improve this answer
    
The OP mentions in the question that crontab -e shows @reboot /opt/restart-hlasic.sh –  Keith Thompson Apr 10 '13 at 19:43
    
yes, I noticed... idea to OP: do you have correct privileges on the script file? –  Fiisch Apr 10 '13 at 19:46
    
Sorry it's restart-hlasic.sh script, it contain code above what I posted and crontab -e contains: @reboot /opt/restart-hlasic.sh as I posted above. Yes it could be way via rc.d but it must be via cron. And file has chmod +x –  MyKE Apr 10 '13 at 19:54
    
You should try to determine if this is a problem with cron or something else. Make just simple script like #!/bin/bash touch /home/somefile plan it for the reboot the same way the restart-hlasic.sh is, reboot and look if the file is created. if it is created, your problem is probably not related to cron :) –  Fiisch Apr 10 '13 at 20:01
    
@Fiisch yeah, I have made simple touch script, added to cron and after restart it made a file, so something is wrong in my script, maybe cron is too fast than other services like mail and NIC? Is there way how to slow down cron for example 30 seconds? –  MyKE Apr 10 '13 at 20:09
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.