Ubuntu – How to run a bash script after 20 sec on Login

bashcommand linescheduledscriptsstartup

I want to run a bash script like:

#!/bin/bash          
echo 'cpu limit bomi player at 40%'
cpulimit -v -e bomi -l 40  

Just 20 seconds after Login into my user. Can you please help me to do that? I searched Google and did what they said but it didn't work for me.

If it's possible for the bash script to run in a new terminal window that will display the output, please tell me what I have to do to achieve that.

Best Answer

A simple way of doing that is to add those lines to rc.local in your system.

For that you need root or sudo rights. You can edit the file with your favourite text editor, eg vim:

vim /etc/rc.local

(sleep 20
echo 'cpu limit bomi player at 40%'
cpulimit -v -e bomi -l 40) &

The first line tells the the computer to wait 20 seconds, the other 2 lines are from your script and the & at the end tells the computer to run that in a sub shell so that your computer does not wait for the function to end and will continue with boot.

You should add those lines anywhere before the exit 0 call at the end of that script since that will make it exit and ignore any lines after that.

Related Question