# Cronjobs

*Quelle: [https://superuser.com/questions/81262/how-to-execute-shell-script-via-crontab/123894#123894](https://superuser.com/questions/81262/how-to-execute-shell-script-via-crontab/123894#123894)*

## Einführung

Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.

<div id="bkmrk-%2A%2F1-%2A-%2A-%2A-%2A-cd-%2Fhome"><div>```
*/1 * * * * cd /home/hacks && sh notify.sh

```

</div></div>To make the script executable, we have to do:

<div id="bkmrk-chmod-%2Bx-home%2Fhacks%2F"><div>```
chmod +x home/hacks/notify.sh

```

</div></div>Here i run this script for every one minute ... By doing below script, you can write it in a log file to find whether its working

write log

<div id="bkmrk-%2A%2F1-%2A-%2A-%2A-%2A-cd-%2Fhome-0"><div>```
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log

```

</div></div>send mail

```
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
```

## Den Server jeden Abend automatisiert herunterfahren

```
server:/ cat /etc/cron.d/shutdown
#tägliches Herunterfahren um 23:00 Uhr
#00 23 * * * root /sbin/shutdown -h now > /dev/null 2>&1

#Montag-Donnerstag um 00:00 Uhr herunterfahren
#00 23 * * 1-4 root /sbin/shutdown -h now > /dev/null 2>&1
0 0 * * 1-4 root date  >> /var/log/_shutdown/shutdown.log
0 0 * * 1-4 root /bin/echo "Fritschserver wird heruntergefahren" >> /var/log/_shutdown/shutdown.log
0 0 * * 1-4 root /sbin/shutdown -h now > /dev/null 2>&1


#Freitag-Samstag um 01:00  Uhr herunterfahren
#00 01 * * 5-6 root /sbin/shutdown -h now > /dev/null 2>&1
0 01 * * 5-6 root date >> /var/log/_shutdown/shutdown.log
0 01 * * 5-6 root /bin/echo "Fritschserver wird heruntergefahren" >> /var/log/_shutdown/shutdown.log
0 01 * * 5-6 root /sbin/shutdown -h now >> /dev/null 2>&1

#Sonntag um 23:00 Uhr herunterfahren
#00 23 * * 7 root /sbin/shutdown -h now > /dev/null 2>&1
#00 00 * * 7 root /sbin/shutdown -h now > /dev/null 2>&1
0 23 * * 7 root date >> /var/log/_shutdown/shutdown.log
0 23 * * 7 root /bin/echo "Fritschserver wird heruntergefahren" >> /var/log/_shutdown/shutdown.log
0 23 * * 7 root /sbin/shutdown -h now >> /dev/null 2>&1
```