Some Scripting Excersises
1.) Using Test Command to find Wether entered Argument is File or Directory. [root@server2 ~]#cat test.sh test -d $1 ks=`echo $?` if [ $ks -eq "0" ]; then echo $1 is Directory; else echo "Entered Argument is not Directory" fi [root@server2 ~]# [root@server2 ~]#./test.sh /etc /etc is Directory [root@server2 ~]# [root@server2 ~]#./test.sh /etc/passwd Entered Argument is not Directory [root@server2 ~]# 2.) Bash For Loop Example for Unzip all the Zip file The following example finds the list of files which matches with “*.zip*” in the root directory, and creates a new directory in the same location where the zip file exists, and unzip the zip file content. # cat zip_unzip.sh #! /bin/bash # Find files which has .zip for file in `find /root -name "*.zip*" -type f` do # Skip the extension .zip dirname=`echo ${file} | awk -F'.' '{print $1}'` # Create the directory mkdir $dirname # Copy the zip file cp ${file} ${dirnam...