File test commands with variable file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File test commands with variable file name
# 1  
Old 10-08-2014
File test commands with variable file name

Hi there

I have the following code
Code:
SDFFILE_SRC=$BACKEND_DIR/$SDFFILE_MIN_tar
SDFFILE_DST=$SIM_DIR/$SDFFILE_MIN
if [[ (-e "$SDFFILE_DST"  && ("$SDFFILE_SRC" -nt "$SDFFILE_DST")) || (! -e "$SDFFILE_DST") ]]
....
....
....
fi

Simply I need to check if $SDFFILE_SRC isa newer than $SDFFILE_DST or $SDFFILE_DST does not exist then execute the IF Body.
Although the the condition is not true, the IF body is executed.
Is there a problem with using file test commands with variable file names ?

Thanks,

Last edited by Franklin52; 10-08-2014 at 11:41 AM.. Reason: Please use regular code tags for multiple lines
# 2  
Old 10-08-2014
Code:
if [[ ! -e "$SDFFILE_DST" || "$SDFFILE_SRC" -nt "$SDFFILE_DST" ]]; then

# 3  
Old 10-08-2014
Does not work either.

I found the problem. In the IF condition body I extract the file $SDFFILE_SRC to $SDFFILE_DST. The extracted file reserves the modification date of the source compressed file.
For example the $SDFFILE_SRC compressed file modification date is @ 11:30am. Whenever I extract it, the extracted file reserves the time 11:30am.
How can I make the extracted file ignore the source file date ?

---------- Post updated at 05:35 PM ---------- Previous update was at 05:30 PM ----------

I found this option
--keep-newer-files
Used for tar upon extraction which keeps newer files. I removed the if condition as it's useless now.


Thanks
These 2 Users Gave Thanks to aelhosiny For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

2. AIX

Change Param File Variable Test Mode Value

First two days of shell scripting... I've looked at awk/sed and man sed only to get off into the weeds of complexity that may not be needed here... hints for awk or sed or other method to magically change the bolded item below? Nutshell: HFTST=Y #test mode = true to false & back again so... (0 Replies)
Discussion started by: JeffPGMT
0 Replies

3. Shell Programming and Scripting

Two question: remove from the other variable or file to get another variable or file

Question 1: A="a b c d e f g 1 2 3 4 5" B="c 3" get C="a b d e f g 1 2 4 5" Question 2: cat file1 a b c (6 Replies)
Discussion started by: yanglei_fage
6 Replies

4. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

5. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

6. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

7. UNIX for Dummies Questions & Answers

How to test commands in files?

Hi. I'm new here, and I'm trying to enter this big world of unix. I would like to know how can I install a SSH server for free so I can teste some things, like make a file, change files, rename and things like this? If is there any easy way to test all commands it would be interesting too. ... (10 Replies)
Discussion started by: whity
10 Replies

8. Shell Programming and Scripting

[Solved] Value of a variable is not recognised for commands comes from external file

Hi, my script is setting a variable with value and this variable is present in my another command that is coming from external file and this command is internally called after this variable is set. but while execution of this command, the value is not retrieved properly. say, my script... (5 Replies)
Discussion started by: rbalaj16
5 Replies

9. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

10. Shell Programming and Scripting

how to test for file existence using file size?

ok im doing this in a normal shell. i need to check the file in the script. how should i write the if else statment? if the filesize contains 0kb then it will echo out file contains nothing else if the script contains more than 0kb then it will echo out file exist. any one care to help?... (3 Replies)
Discussion started by: forevercalz
3 Replies
Login or Register to Ask a Question