Visit Our UNIX and Linux User Community


Timestamp copying giving file path and name as inputs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Timestamp copying giving file path and name as inputs
# 1  
Old 05-02-2011
Bug Timestamp copying giving file path and name as inputs

PLAESE CHECK WHETHER THIS SCRIPT WORKS OR NOT.
THIS IS MY FIRST SCRIPT, HELP ME out if any ERRORS are present.





Code:
a=0;
while [$a -eq 0] 
do 

echo "ENTER path"
read path
if [ -e $path ] then
echo "path found"
cd $path

DateTimeStamp=$(date '+%d_%m_%y_%H_%M')
echo "enter file name"
read file
if [-e $file] then
echo "file exists"
cp ${path}/${file} ${path}/${file}_bkp_${DateTimeStamp}
echo "file backup created using file name ${path}/${file}_bkp_${DateTimeStamp}"

chmod 755 ${path}/${file}_bkp_${DateTimeStamp} 
else
echo "file doesnot exist"
a=1;
fi
else
echo "path does not exist"
a=1;
fi
done


Last edited by pludi; 05-02-2011 at 06:10 PM..
# 2  
Old 05-02-2011
  1. Please use code tags for code.
  2. Indent your code so it is readable.
I have indented and used the [highlight=shell] so that it is nicely coloured:
shell code:
  1. a=0;
  2. while [ $a -eq 0 ]     # Needs SPACE there
  3. do
  4.     echo "ENTER path"
  5.     read path
  6.     if [ -e $path ]; then    # You forgot a ';' here
  7.         echo "path found"
  8.         cd $path
  9.         DateTimeStamp=$(date '+%d_%m_%y_%H_%M')
  10.         echo "enter file name"
  11.         read file
  12.         if  [ -e $file ]; then    # here too ! and needs SPACE
  13.             echo "file exists"
  14.             cp ${path}/${file} ${path}/${file}_bkp_${DateTimeStamp}
  15.             echo "file backup created using file name  
  16.             ${path}/${file}_bkp_${DateTimeStamp}"
  17.             chmod 755 ${path}/${file}_bkp_${DateTimeStamp}
  18.         else
  19.             echo "file does not exist"
  20.             a=1    # no need of ';' here
  21.         fi
  22.     else
  23.         echo "path does not exist"
  24.         a=1    # no need of ';' here
  25.     fi
  26. done
# 3  
Old 05-03-2011
Thanks frans Smilie Smilie .... and thanks for explaining my mistakes Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #797
Difficulty: Easy
The simplest arithmetic operation in binary is addition.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Preserve destination timestamp while copying

Hi Guys, I am trying to copy a file from source to destination, I need to preseve timestamp of destination cd desitnation ll file.txt Aug 17 17:22 file.txt cp -p source/file.txt destination/ I need to preseve same timestamp after copying cd desitnation ll file.txt Aug 17... (9 Replies)
Discussion started by: rohit_shinez
9 Replies

2. Shell Programming and Scripting

Need help: Script to report timestamp of directories in a specific path from multiple Linux server

Need help Please help on how to write a script which can echo timestamp, size of subdirectories in a specific path from multiple Linux servers to a text file. I can ssh with a common user to all the servers from a build box. Basic idea what I had was: ssh <commonuser>@<each box> cd... (1 Reply)
Discussion started by: sudhichadaga
1 Replies

3. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

4. UNIX for Dummies Questions & Answers

latest files copying over to new path

ls -lrt | nawk -v D="$(date +'%b%e:'| sed 's/ //g')" 'D==$6$7":"{sub(".*"$9,$9);print}' This picks only the latest files created based on the timestamp for that particular day.. how do i copy over the same files to a different location???? (1 Reply)
Discussion started by: win4luv
1 Replies

5. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

6. Windows & DOS: Issues & Discussions

DOS Dir - listing of full path and timestamp

Hi, (Apologies, I'm sure I'm not the first person to raise this question but so far in my searches haven't found a good answer). I would like to output a listing per line of filename (including full path) and 'last updated' timestamp. e.g: Z:\dir1\file1.txt 01/02/2010 10:43... (5 Replies)
Discussion started by: GM_AIX
5 Replies

7. Shell Programming and Scripting

copying a list of files from one machine to another with the same path

Hello All, I would like to download a list of files from a remote server to my local machine preserving the path i.e, create a similar directory tree. ex: files on the remote machine with path /remoteserver/005_S_0221/mpr/m1/I72128/dat/06A515T.dat... (3 Replies)
Discussion started by: avatar_007
3 Replies

8. Shell Programming and Scripting

How to read inputs from a file

Hello; Please I need to read inputs from a file change 1 or 2 things the output to another file. (1 Reply)
Discussion started by: jimoney
1 Replies

9. Shell Programming and Scripting

copying unreference files and keeping absolute path

Hi guys, I'm creating a script that basically remove unreference files so at the moment I have something like: DAYS=30 for DIRECTORY in `mount | awk '{ print $7}'` do find $DIRECTORY -type f -atime +$DAYS < ~/files.log done for FILE in `awk '{print $1}' ~/files.log` do cp... (2 Replies)
Discussion started by: hariza
2 Replies

10. Shell Programming and Scripting

Inputs from a file

Hi, I have a shell script that has to taken inputs from a file say "Inputs". Now I take 2 inputs at a time. Suppose the Inputs file contains numbers like 2 3 4 5 Now I have a written a script for adding 2 numbers. When I run the script for first time 2 and 3 must be the inputs. When i run the... (4 Replies)
Discussion started by: sendhil
4 Replies

Featured Tech Videos