Exercise 01
Backup script for the sysconfig directory
STEP 1
create file using vi editor backup-sysconfig.sh
[root@server ~]#vi backup-sysconfig.sh
step 2
paste the following script
#!/bin/bash
# This script creates a backup of /etc/sysconfig
# into a datestamped subdirectory of ~/backups/
cp -av /etc/sysconfig ~/backups/sysconfig-$(date '+%Y%m%d')
echo "Backup of /etc/sysconfig completed at: $(date)
step 3
copy this file from home directory to the /bin
step 4
create the backup directory on the root home directory
[root@server ~]#mkdir backups
step 5
make this file executable by writing the following command
[root@server ~]#chmod u+x ~/bin/backup-sysconfig.sh
step 6
You are now ready to try out your script. You should see something like the following:
[root@server ~]# backup-sysconfig.sh
`/etc/sysconfig' -> `/root/backups/sysconfig-20100102'
`/etc/sysconfig/pand' -> `/root/backups/sysconfig-20100102/pand'
`/etc/sysconfig/ipmi' -> `/root/backups/sysconfig-20100102/ipmi'
`/etc/sysconfig/rhn' -> `/root/backups/sysconfig-20100102/rhn'
`/etc/sysconfig/rhn/up2date' -> `/root/backups/sysconfig-20100102/rhn/up2date'
`/etc/sysconfig/rhn/clientCaps.d' -> `/root/backups/sysconfig-20100102/rhn/clientCaps.d'
`/etc/sysconfig/rhn/rhnsd' -> `/root/backups/sysconfig-20100102/rhn/rhnsd'
`/etc/sysconfig/kudzu' -> `/root/backups/sysconfig-20100102/kudzu'
`/etc/sysconfig/dund' -> `/root/backups/sysconfig-20100102/dund'
step 7
Now check the backup directory
[root@server ~]# cd backups/
[root@server backups]# ls
sysconfig-20100102
[root@server backups]# cd sysconfig-20100102/
[root@server sysconfig-20100102]# ls
apmd crond ip6tables-config modules sendmail
apm-scripts desktop ipmi network smartmontools
auditd dund iptables networking spamassassin
authconfig firstboot iptables-config network-scripts squid
autofs grub irda ntpd syslog
bluetooth hidd irqbalance pand system-config-securitylevel
cbq httpd kdump prelink system-config-users
clock hwconf kernel readonly-root tux
conman i18n keyboard rhn vncservers
console init kudzu saslauthd wpa_supplicant
cpuspeed ip6tables mkinitrd selinux
Thursday, December 31, 2009
Exercise 01 Bash scripting Practical Examples
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment