9

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.

Mahdi
  • 91

3 Answers3

13

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.

Bruno Pereira
  • 74,715
0

You could also enter this in the terminal:

crontab -e

and then type this in:

@reboot /path/to/script

and in the script type in at the beginning this:

sleep 20

and it might work fine this way.

A.B.
  • 92,125
Michael
  • 2,597
-1

Another suggestion is to create executable bash script. Lets call it onboot.sh and save it in your home directory

~/onboot.sh

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

then make it executable by running this command

chmod +x ~/onboot.sh

then add this line to your ~/.bashrc

~/onboot.sh &

Every time you create a new terminal session it will run ~/.bashrc which will then run your ~/onboot.sh file.

EDIT: Forgot to mention that this will only run for that particular user. not for all users on the system.