Skip to main content

Posts

Showing posts from August, 2019

Copying file from One directory to Another in Unix

copy_file{ for file in \MyDrive\MyFolder\   do   echo $file   FILESIZE=$(stat -c%s $file)   echo "filesize " $FILESIZE     if [[ "$FILESIZE" -eq 0 ]]         then            echo "$file is empty.Hence not sending it.Can't Execute further"           exit 1         else          echo "$FILE has data."     fi   echo "Copying File "   cp  $file $Other_Directory } #************Starting Copy File String# copy_file

FTP using Unix Shell Scripting

For doing FTP what u need in unix is Username and password and server path where you are transferring file. send_viaftp(){ ftp -ni $destination verbose user $username $password cd $destinationfolder ascii put $myfile } #Copying file  to server2 destination=server2 destinationfolder=home/test username=test password=tst$888 send_viaftp

Getting started with Unix

chmod +x test.sh this is the command used to make file executable To execute File ./test.sh Date used to get date date Creat a file vi hello.sh inser code esc + I Save code  and quit esc + :wq if file is readonly use :wq! Give access to execute chmod +x hello.sh       or      chmod 755 hello . sh Execute Script ./Hello.sh See what is the content of this file cat Hello.sh Exporting values in Unix for Variables I have a script echo " VAR VALUE IS $VAR1" $VAR1="hello" echo"NEW VAR VALUE IS  $VAR1" output run using ./hello.sh Var value is New var value is hello if you define  $VAR in command prompt before running $VAR = OLDHELLOW It wont recognize this running ./hello and out put will be same run using ./hello.sh Var value is   New var value is hello To make it global we need to export this value using export VAR run using ./hello.sh Var value is  oldhello New var value is