Register
It is currently Wed Dec 13, 2017 10:58 am

shell script - archive tar script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed Dec 14, 2016 3:20 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
hi all,

made a script and thought i would show you guys about it,


Code:
#!/bin/bash

   echo "is this archive for an audio tar (press 1) or an audio directory (press 2)"
   read method

   case $method in
      1)
         echo "please specify full path to tar file"
         read -e tar

         base=$(basename "$tar")

         echo "please enter ID number ie ID1234"
         read id

         echo "please specify where you want the tar file to be stored"
         read -e dest

         if ! mv "$tar" "$id"_"$base" ; then
            echo "something went wrong with the mv command, please do manually"
            exit
         fi

         if ! rsync -avh "$id"_"$base" "$dest" ; then
            echo "something went wrong with the rsync command, please do manually"
            exit
         fi

         if ! rm -f "$id"_"$base" ; then
            echo "something went wrong with the rm -f command, please do manually"
            exit
         fi
            
         ;;

      2)
         echo "please specify full path to directory you want to be made into a tar"
         read -e dir

         cd $dir
         cd ..

         base=$(basename "$dir")

         echo "please enter ID number ie ID1234"
         read id

         echo "please specify where you want the tar file to be stored"
         read -e dest

         if ! tar -cf "$id"_"$base".tar "$base" ; then
            echo "something went wrong with the tar, please do manually"
            exit
         fi

         if ! rsync -avh "$id"_"$base".tar "$dest" ; then
            echo "something went wrong with the rsync, please do manually"
            exit
         fi

         if ! rm -f "$id"_"$base".tar ; then
            echo "something went wrong with the rm -f command, please do manually"
            exit
         fi

         if ! rm -rf "$dir" ; then
            echo "something went wrong with the rm -rf command, please do manually"
            exit
         fi

         ;;

      *)
         echo "invalid selection, please re-run the script"
         exit

         ;;

   esac


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP