Solved

bash scripting question

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
control image tags in a string ? 12 141
MacOS and programming in React 7 41
Run AutoHotkey script directly from Notepad++ 5 59
Vector, list Questions R 6 31
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 …

840 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