run a script when shutdown computer
Hello all!!
Hope I am in right forum and so.
Well. I have created a small script I can run sometimes to free some space from computer.
I have created a file "rensa.bin"
Code:
rm -rf /home/erik/.thumbnails/normal/*
rm -rf /home/erik/.thumbnails/fail/gnome-thumbnail-factory/*
rm -rf /home/erik/.Trash/*
rm -rf /home/erik/.mozilla/firefox/pl7hilo9.default/Cache/*
I have made it executable on the desktop. It runs a command "sh rensa.bin"
I can use this script and it erase the contents in these directories.
This is not so important but I think its fun to make something automatic.
I wonder how do I integrate this script when computer shutdown?
So I dont need to run from desktop...
Re: run a script when shutdown computer
On shutdown: don't really know, sorry
My advise would be to setup cron to execute that script let's say, every 2 hours.
https://wiki.ubuntu.com/CronHowto
Re: run a script when shutdown computer
In the UNIX world, such shell scripts normally begin with a "shebang" line:
and the filename gets the suffix '.sh'. Then you can just mark it executable:
and you can just run it as is (if it exists somewhere in your command path) without having to say 'sh rensa.sh'.
To have it run at shutdown, this should do it:
Code:
sudo cp rensa.sh /etc/init.d
sudo ln -s /etc/init.d/rensa.sh /etc/rc0.d/K10rensa.sh
sudo ln -s /etc/init.d/rensa.sh /etc/rc6.d/K10rensa.sh
For some background as to why this works:
An introduction to run-levels
Re: run a script when shutdown computer
Re: run a script when shutdown computer
Is it necessary to put the script in int.d for running it on shutdown?
Re: run a script when shutdown computer
Can't you put in a script to reboot or shutdown the computer? like sudo reboot/ sudo shutdown?
Re: run a script when shutdown computer
umm..i am not sure i understand what you mean..?
Re: run a script when shutdown computer
Quote:
Originally Posted by
linuxnovice
Is it necessary to put the script in int.d for running it on shutdown?
The script has to be in /etc/rc{0,6}.d to run on shutdown and reboot. Convention is for the script itself to live in /etc/init.d and for there to be symlinks to it from the proper rc*.d directories. You should follow the convention unless you have a very good reason for doing otherwise.
In Ubuntu, there's another method available: Upstart. Upstart is event-based, and theoretically more flexible. I've never messed with it, though, so I couldn't tell you how to use it.
Re: run a script when shutdown computer
Quote:
Originally Posted by
linuxnovice
umm..i am not sure i understand what you mean..?
He/She means that you just copy your commands to a script, append the command to shutdown the computer and in the future use this script to shotdown the computer instead of the usual GNOME System->Quit menu command or whatever.
For adding your script to the boot sequence, look at http://ubuntuforums.org/showthread.p...ghlight=bootup
this post by me - It tells you how to install a custom script to the bootup&shutdown sequence. It also tells you how to revert these changes. Note that your script will then be run at bootup&shutdown. However, you can check what is the case. So your code should look like:
PHP Code:
#!/bin/bash
if [ "$1" = "stop" ]
then
....
fi
Re: run a script when shutdown computer
no longer participating in ubuntuforums.org