Solved

bash scripting question

Posted on 2006-11-26
4
186 Views
Last Modified: 2010-04-16
i have a script that copies an archive from another folder on the server cp /pub/file.tgz .
how do i make so that if the file, is already there but unpacked, the script would check if the file exists
and automatically notify the person running the command, and ask for a new folder creation, and then the process to move to the new folder created
0
Comment
Question by:rares_dumitrescu
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18015333
if [ -e $file ] ; then
  echo file exists
  read -p 'new folder:' folder
fi
 
0
 
LVL 8

Expert Comment

by:jk2001
ID: 18017238
Do you know the contents of the file before you unpack it?
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18019307
if fear you must build a list of the files in the tar check if all are there and then ask:
folder="/home/myfolder"
list=`tar tfz $folder/file.tgz`
for i in $list; do
if [ -e $file ] ; then
  echo file exists
  read -p 'new folder:' folder
break;
fi
done
cd $folder
cp /pub/file.tgz .
 tar xfz file.tgz
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now