Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My script is located in /opt/ contains:

# Line divider
# Put the email together
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/

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

share|improve this question

migrated from Apr 11 '13 at 0:17

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

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
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/ which has #!/bin/bash, so the command executed by sh is effectively /bin/bash /opt/ – Keith Thompson Apr 10 '13 at 23:07
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/ – 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 script, it contain code above what I posted and crontab -e contains: @reboot /opt/ 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 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .