Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-14-2006, 09:22 PM
|
#1
|
LQ Newbie
Registered: Jun 2004
Distribution: Gentoo
Posts: 15
Rep:
|
Gentoo Shutdown Script
Hi,
I would like to begin running a backup script on my system to keep some of my critical files backed up. The backups involve tar`ing and bzip`ing about 300 MB worth of files, so it is somewhat resource consuming while running, meaning having it run on cron while the system is in use would become irritating when the system slows to a crawl for a few minutes when I'm in the middle of something.
So, I want this backup to run at system shutdown because I could care less if my system is slow to shut down (given that, if I'm shutting it down, that probably means I'm done using it!). Also, I would like the ability to enter 'y' or 'n' to tell the script if it is going to create a backup or just skip it.
So, two questions: How would I write a script to execute automatically on system shutdown in Gentoo, and how would I write such a script to include a prompt?
Thanks.
|
|
|
05-14-2006, 09:58 PM
|
#2
|
Senior Member
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555
Rep:
|
Something to the effect of
----------------------------------------------------
echo -n "Do you want the backup script to run: "
read Answer
if [ "$Answer" = "y" ]; then
tar cvjf backup.tar /whatever/directory/you/want
else
echo "Backup skipped"
fi
----------------------------------------------------
Now this is not complete or syntactfully correct, I don't have a linux box at work to write/test a script to be correct but this should give you the basic outline. The READ is what allows you to get input from a prompt. Also, this will fail if you don't enter a lowercase 'y', you could build in checks to help prevent that error. Also, anything that isn't a lowercase 'y' is a No which is another bad coding, but like a said this is a quick and dirty version.
Last edited by musicman_ace; 05-14-2006 at 10:01 PM.
|
|
|
05-14-2006, 11:02 PM
|
#3
|
Member
Registered: Dec 2005
Distribution: Slackware
Posts: 250
Rep:
|
You should have something like rc.0 script in /etc/rc.d or /etc/init.d ( I'm not really sure how it is named on gentoo ). This is the script executed on shutdown. You could put at the beginning of it, or whenever you like ( don't know if you have some database running which you would like to have closed uring backup. ) Just be careful taht necessary services are still running.
|
|
|
05-15-2006, 02:29 AM
|
#4
|
Senior Member
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555
Rep:
|
oops, I left that out. In gentoo, you'll need to stick that script in the local.stop file in /etc/conf.d directory.
If you then to rc-update -s and look at local, it should be active for the default runlevel
Last edited by musicman_ace; 05-15-2006 at 02:31 AM.
|
|
|
05-15-2006, 07:12 AM
|
#5
|
LQ Newbie
Registered: Mar 2004
Location: INDIA
Posts: 6
Rep:
|
Hi
I think thats a wonderful question as a matter of fact....Sys Admins do require these kind of scripts....
regards
Manish
|
|
|
All times are GMT -5. The time now is 07:22 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|