Crontab entry for a bash file

Hi All,

This is for Ubuntu Server 22LTS

Would like some assistance with a crontab entry for a small bash file that I would like to run every 15 minutes.

The bash file is located in my home folder “/home/user/bash.sh”
And I run it manually when it enter"./bash.sh" from the home folder.

Can’t quite understand the environment entries from the cron help pages.

Regards

Please be precise with details, as per Support and Help guidelines

You don’t clearly specify if this is Ubuntu Core 22 [Server] (LTS is implied as all Core/year products are LTS) or Ubuntu 22.04 LTS Server.

You forgot to post the actual entry from your crontab file which would help others to help you. When you run it manually, does it succeed? The link below gives a pretty detailed explanation of using crontab with examples which should help.

https://www.geeksforgeeks.org/linux-unix/crontab-in-linux-with-examples/

1 Like

A line to run the script every 15 minutes is:

0,15,30,45 * * * * /home/user/bash.sh

It can be probably be written nicer and more compact.

1 Like

For instance:

0/15 * * * * /home/user/bash.sh

1 Like

Just use the crontab -e command as the user you want the script to run as … that will spawn your default editor (or give you a choice of editors if you do not have one yet) and open a user crontab with a descriptive comment block at the top that explains the fields and what to put in them … once you save the file in your editor it will verify it for typos and make sure what you put into it is valid … (both examples @wgarcia gives above are indeed valid, but it is always helpful to use the tools the maintainers of a package have intended for it (and the mentioned comment block should actually help you understand it a bit better too))

2 Likes

What use does it need to run as? This is important. Does it need root access? Does it need a GUI running and so on.

Wow Thank you all for your input

Currently I Have in the cron

*/15 * * * * /home/user/./md1200.sh >/dev/null 2>&1

This bash file is for controlling the fan speed on my Dell disk shelf.

Currently, Everytime, I manually have to enter:

./md1200.sh

to control the fan speed, but the fans do crank up to 100% speed on it’s own. So I have to manually enter it command again.

It does not require su privileges. Nor, it has not GUI as it is on my Server Ubuntu 22.04.5 LTS.

I figure every 15 minutes for the cronjob should be able to keep it at my manual override set speed (10%)

The bash file:

#!/bin/bash
stty -F /dev/ttyS0 38400 raw -echoe -echok -echoctl -echoke
echo -e -n 'set_speed 10\r' > /dev/ttyS0
sleep 2
echo -e -n 'set_speed 10\r' > /dev/ttyS0
sleep 2
echo -e -n 'set_speed 10\r' > /dev/ttyS0
sleep 2
echo -e -n 'set_speed 10\r' > /dev/ttyS0 

Seems to be working manually

Sounds like you are actually asking for producing a hardware failure …

Blindly just forcing the fan speed down without at least checking the temperature value to make sure you do not damage your disks will clearly not do your hardware any good.

I’d extend the script to do some temp reading before enforcing a fan value so you do not accidentally turn it down while the disks are actually overheating…

Is there a particular reason you call the set_speed four times in succession instead of once ?

What I would do if I was you would be to turn the script into an actual daemon by using a systemd timer that fires every 15min, switch the script itself to use /bin/sh instead of bash (there is no need to load a wasteful 5MB shell binary into ram when you do not use bash specific scripting, /bin/sh will just do the same but a lot faster and with eating less RAM) and add some actual temperature check to the script before enforcing any fan speed changes …

This topic was automatically closed after 30 days. New replies are no longer allowed.