cp command evaluation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cp command evaluation
# 1  
Old 04-29-2011
cp command evaluation

Hi all!

I'm writting one script to copy a file in various folders, but there are 2 things to validate. First that the folder where i'll be cpying exists, and second that i have permissions to copy the file in it.
so far i have found the way to validate the folder exists, but when trying to copy it, don't know how to validate if it was copied, since if I don't have permission to see the folder i wont be able to do ls | wc -l
this is the code:

Code:
if  [ -d $UIXMLDEVENG ] ; then
   echo 
else
   echo "PATH $UIXMLDEVENG does not exist">FinalLog.log
   exit 0
fi

cp $PRUEBA $UIXMLDEVENG

how to validate either the folder is there and have permissions not only to see it but also to copy a file inside of it???

Thanks!!!

Last edited by pludi; 05-03-2011 at 05:53 AM..
# 2  
Old 04-30-2011
Have you thought to change the permission of the file so you can read it?

chmod +r File

then cat into it.
# 3  
Old 04-30-2011
Quote:
Originally Posted by Shaun74
Have you thought to change the permission of the file so you can read it?

chmod +r File

then cat into it.
I can't with the user i'm logged, the idea it's not to read a file, sorry if I didn't make myself clear, the idea is to evaluate if the destiny folder is available, and if so, if I have permissions to copy a file inside.
Thanks anyway Shaun.
# 4  
Old 05-01-2011
If in correct directory

ls -al

look for file, see the chmod on left? See if you have the permissions. If the file does not appear, it is not available. At least not in that directory. Can you get into su? if not, and you are not the file owner - I cant help you.
# 5  
Old 05-01-2011
If i understood correctly..

Check man test :
Code:
      -w FILE
              FILE exists and write permission is granted

Code:
$ls -dl test
dr-xr-xr-x 2 user group 4096 2011-05-01 08:32 test
$test -w test
$echo $?
1
$chmod 655 test
$ls -dl test
drw-r-xr-x 2 user group 4096 2011-05-01 08:32 test
$test -w test
$echo $?
0

This User Gave Thanks to Peasant For This Post:
# 6  
Old 05-02-2011
Quote:
Originally Posted by Peasant
If i understood correctly..

Check man test :
Code:
      -w FILE
              FILE exists and write permission is granted

Code:
$ls -dl test
dr-xr-xr-x 2 user group 4096 2011-05-01 08:32 test
$test -w test
$echo $?
1
$chmod 655 test
$ls -dl test
drw-r-xr-x 2 user group 4096 2011-05-01 08:32 test
$test -w test
$echo $?
0

Thank you very much! It worked just fine!

---------- Post updated at 10:38 AM ---------- Previous update was at 09:49 AM ----------

Now, another issue, how to do the same validation on a file which is in a remote server, using the same shell script??, maybe by using telnet, ssh or even ftp???
how could it be possible?
Thanks!!!
# 7  
Old 05-02-2011
Code:
ssh USERNAME@SERVERNAME "the command"

This User Gave Thanks to rdcwayx For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Evaluation of test command

Could somebody please explain to me why and how the highlighted line(s) (?) of code puts the "test" evaluation into "result" and then to $enable_static ? Or does not ? I did comment out the original code and changed it to what I feel is less cryptic , but the "result" is still wrong =... (3 Replies)
Discussion started by: anne
3 Replies

2. Shell Programming and Scripting

Help understanding evaluation order

I have made a simple script to find all programs that use a tcp wrapper, it will supply a reasonable default for my system if none is given. After some digging I realized that the expansion operators pass their default return value single quoted (according to bash -x trace). I have wildcard... (2 Replies)
Discussion started by: phuongnguyen
2 Replies

3. Shell Programming and Scripting

Help understanding evaluation order

I have made a simple script to find all programs that use a tcp wrapper, it will supply a reasonable default for my system if none is given. After some digging I realized that the expansion operators pass their default return value single quoted (according to bash -x trace). I have wildcard... (0 Replies)
Discussion started by: Riker1204
0 Replies

4. Shell Programming and Scripting

How to Force command substitution evaluation in bash?

OK, I'm striving to abide by all the rules this time. Here is a fragment of my windows10/cygwin64/bash script: export BUPLOG=$(BackupRecords --log "$src") robocopy $(BackupRecords -mrbd "$src" --path "$src") $(BackupRecords --appSwitches "$src") "$src" "$dst" $(BackupRecords --fileSwitches... (15 Replies)
Discussion started by: siegfried
15 Replies

5. Shell Programming and Scripting

How to Force command substitution evaluation in bash?

OK, I'm striving to abide by all the rules this time. Here is a fragment of my windows10/cygwin64/bash script: export BUPLOG=$(BackupRecords --log "$src") robocopy $(BackupRecords -mrbd "$src" --path "$src") $(BackupRecords --appSwitches "$src") "$src" "$dst" $(BackupRecords --fileSwitches... (0 Replies)
Discussion started by: siegfried
0 Replies

6. Cybersecurity

iptables latency evaluation

Hello guys, I'm actually working on my master thesis which has for subject the evaluation of virtual firewall in a cloud environment. To do so, I installed my own cloud using OpenNebula (as a frontend) and Xen (as a Node) on two different machines. The Xen machine is my virtual firewall thanks... (2 Replies)
Discussion started by: Slaughterman
2 Replies

7. Shell Programming and Scripting

Using AWK in IF evaluation in KSH

Hi - I have an expression that evaluates to "Alive" or some other condition. e.g. if I run :- awk -F \| '{gsub(/]*/,"",$4); print $4 }' then the output is "Alive". I want to be able to test this as the result may be some other condition other than "Alive". I have tried the following... (4 Replies)
Discussion started by: sniper57
4 Replies

8. Shell Programming and Scripting

AWK equation evaluation.

Hi, Is there a way to evaluate an equation contained in a string within an AWK script? For example: A = "(5*2)-1" (this equation is read from a file and varies line by line) In this example, I can't see any way to get an answer of 9 unless I do: cmd = "awk 'BEGIN{print "A"}'" cmd |... (3 Replies)
Discussion started by: srdgeo
3 Replies
Login or Register to Ask a Question