Shell script which will check the target file and folder exists and copy it
Hi All,
I am a beginner in this and trying to write a shell script in linux which will :
1. Ask for a file name and check if its exists.
2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists.
3. If target folder exists it will copy that file in to it.
I have written the below code and it's working fine if file and folder exists but not working properly when any of them is not exists.
Moved the if [ -d "${location}" ] inside the first successful if statement, since it is the only place that belongs, otherwise it will execute even when it is established that the file doesn't exist. The only thing I added for you to ponder is the if [ $? -eq 0 ];. Assuming that cp is successful is not truthful to the following echo.
1. Ask for a file name and check if its exists.
2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists, if doesn't exits it will create one with with the $location value.
3. It will copy that file in to it.
I have made below changes in to above script. Its working but i facing minor issue in it:
If i am trying to copy existing file in to non existing folder it's working fine and throwing below message
But if i am copying existing file in to existing folder i am not getting above message.
I will really appreciate if you point out needed changes.
I need help to write shell script to copy files from one server to another server.
Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Hi,
When trying to chk if a folder exists on remote server using the below command (got it from other thread in this forum)
"ifvchr@s1.mrix.local '/cygdrive/d/shares/projects\ data\ load/test\ files/$SCPED_FILES$name$code'`];
then
echo "Directory exists";
else
echo "Directory... (0 Replies)
HI all,
I want to script where all the server names will be in a text file like
server1
server2
server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Hi,
Below is some code that I would like to implement however I am getting these errors: (what I am attempting to do is to check if a zip file has ascii files and if ascii and not binary then move the ascii files to a folder. some of the files are in xml format but are ascii and i will be moving... (0 Replies)
Hi everyone. I am trying to write a bash script that will copy files from one directory to another but I need to be able to check the directory that I'm copying the files to and see if the file already exists. If it does I need to add a number at the end of the copied file. Thanks for your help. (3 Replies)
Hi All,
working on AIX 5.3.
Requirement is:
Shell script in ksh to check if any file exists in 4 folders as below:
1. /FILE/INB/INT1
2. /FILE/INB/INT2
3. /FILE/INB/INT3
4. /FILE/INB/INT4
Thanks a lot for your time!
a1_win. (3 Replies)
Hi friends..
I hav a problem....
I dont know how to check .c files exists r not in a folder using IF in C shell script
actually i tried like this
if(=~ *.c)
even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
hi,
I posted a thread before on that subject, but with a wrong focus...
here's my problem: I want to check if a file exists in a windows shared folder mounted using:
sudo mount -t cifs -o username=xxx,password=xxx,uid=xxx,gid=xxx //192.168.0.92/public /media/92_shared
I tried
if
... (2 Replies)
Hi, I have cobbled together a simple script to create a Windows folder in a bunch of home folders on a mac server using the following code.
for i in /Volumes/student_data/studenthomefolders/*
do
u=`echo $i | cut -d/ -f5`
//if
//then
//echo "Folder already exists for "$u" Skipping"
//else... (4 Replies)
Hi,
I want to sftp some files to a remote directory. Before transferring files i want to check whether the required folder exists. If so copy the files to that folder, else create the folder and copy the files.
Thanks in adv (1 Reply)