Solved

bash scripting question

Posted on 2006-11-26
4
173 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

19 Experts available now in Live!

Get 1:1 Help Now