Go Back   Web Server Hosting Forum by BODHost > Support > Linux Server Hosting
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-20-09, 09:57
BOD Member
 
Join Date: Jan 2009
Posts: 73
Default Using shell scripts and alias to make life easier.

One of the most beautiful things about linux is the ability to create scripts that combine multiple commands into one. Another is that you can use alias to create commands that execute with switches by default.

Lets say you would like 'ls --color' to happen every time you typed 'ls'
just add an alias to your .bash_profile.

Code:
alias 'ls' = 'ls --color'
Simple.

Next, lets say that every day you make a backup of a directory and move it to a directory called backup.
Instead of typing in all the commands every day you simply create an executable in your path with the commands inside it. You now have a script called backup with something like the following code inside it -

Code:
#!/bin/sh
####
# backup the directory structure and move it to the backup folder
####
tar -vxzf backup_dir.tar.gz /home/mysite/public_html
mv backup_dir.tar.gz /backups
Simple.
Now when you type backup it will create a backup and move it to the backup folder automatically.

You can use this to create automatic backups of anything, you can even adapt the code and have it send emails with the backup as an attachment =)

I have a bin directory with about 150 scripts that I use all the time, and I have them backed up and sent to my email account, just incase I need them one day and my server dies!
Reply With Quote
  #2 (permalink)  
Old 02-20-09, 16:04
carl owen's Avatar
Super Moderator
 
Join Date: Nov 2008
Posts: 1,059
Default

Shell scripts are really a very good advantage with Linux. They make it easier for your to manage your server once you have learned them. The information provided above is really useful and Thank you for the same php_rules :D
Reply With Quote
  #3 (permalink)  
Old 02-21-09, 15:08
BOD Member
 
Join Date: Jan 2009
Posts: 51
Default

Thanks for the code snippets. I am new to the linux shell, but I am learning quickly. I think I may try your backup script out and see if I can get it to work for me.
Reply With Quote
  #4 (permalink)  
Old 03-01-09, 05:42
BOD Member
 
Join Date: Jan 2009
Posts: 172
Default

Hello php_rules, this is very helpful. I didn't know how to use shell scripts and alias and learn how to save my commands in a script called backup script. Thank you for sharing this to us.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 03:09.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.