LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 12-14-2016, 03:21 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
shell script - archive tar script


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
 
Old 12-14-2016, 07:32 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,888

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
in general:
usually we send error messages to stderr instead of stdout
usually the exit code is 0 when everything is ok and non-zero in case of any error.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script Archive entpacken Tealk144 Programming 8 06-29-2014 04:51 PM
Shell Script how to remove absolute paths from zip archive hi_irf Linux - Newbie 1 10-03-2009 05:59 AM
How about a shell script archive? Autocross.US LQ Suggestions & Feedback 2 12-05-2006 06:36 PM
tar error in shell script fanoliv Programming 4 11-04-2006 03:52 AM
shell script - add file to archive ? xconspirisist Linux - Software 2 03-20-2004 03:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration