Sponsored Content
Top Forums Shell Programming and Scripting Problem with mv command and touch command Post 302508796 by Antcam on Tuesday 29th of March 2011 05:12:30 AM
Old 03-29-2011
Each one of these 2 step run an external command (in this case unix scripts), so the behavior should be like you were running these scripts from shell.

The code of the original movedate.sh is :

Code:
#!/bin/sh

usage()
{
    echo "USAGE: $0 <file1> <file2>";
    echo "    sposta il file <file1> nel file <file2>.";
    echo "    Il file <file2> non deve esistere.";
    echo "";

    case $1 in
        2) echo "Numero errato di parametri: $#";;
        3) echo "Il file <file2> non deve esistere";;
        4) echo "File non trovato";;
        *) echo "Errore non documentato";;
    esac

    echo "Return code $1";
    exit $1;
}

#echo $ORACLE_SID

# set the default_path where the parametres of the scripts should be located

DEFAULT_PATH=/usr/sap/${ORACLE_SID}/ifr
DATE_TIME=$(date +%Y%m%d%H%M%S)

# If the number of the parametres are not correct, exit with error

if [ ! $# -eq 2 ] ; then
    echo $#
    usage 2
fi

# If file <file2> exists, exit with error
if [ -f $DEFAULT_PATH/$2 ] ; then
    usage 3
fi

#origin path where the file is
path1=$DEFAULT_PATH/$1

#destination path where the file shold be moved
path2=$DEFAULT_PATH/$2

#If the file that has to move does not exist, exit with error.
if [ ! -f $path1 ] ; then
    usage 4
fi

for file in $path1; do
        mv $file $file$DATE_TIME
        
        #origin path without the name of the file
        path_1=${path1%/*}
        
        #destination path without the final "/"
        path_2=${path2%"/"}
        
        #confrontation of destination path and origin path, if different the file is moved, otherwise only the time and date is added to the name of the file.
            if [ ! $path_1 = $path_2 ]; then  
                mv $file$DATE_TIME $DEFAULT_PATH/$2
                echo "Moving the file " $file "... done!"
                else echo "origin path and destination path are the same, only time stamp added to the file... done!"
            fi    
done

----End of script---

I used a for cycle because mmv command because it isn't.
In default_path there is the variable ORACLE_SID, so only particular users can run the script (only who has this environment variable set)

The touch script called "ytouch.sh" does the following things:



Code:
#!/bin/sh
.
#other stuff, setting default_path and usage like number of parametres passed to the scripts
.
.
.
#check if the file that has to be created already exists
if [ -f $DEFAULT_PATH/$1]; then
     usage 3  #exit with error
fi

touch $DEFAULT_PATH/$1


Last edited by radoulov; 03-29-2011 at 06:21 AM.. Reason: Code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of Touch Command

HI all, I am wrkin on HP Unix .. can any1 let me know da usage of Touch command in shell scripting (1 Reply)
Discussion started by: ravi.sadani19
1 Replies

2. UNIX for Dummies Questions & Answers

touch command

hello everyone i am new to this forum and was wondering if you all could help me out.... i am looking for a touch command that can touch directories as well as files that does not involve sygwin... any and all help would be appreiciated :D (3 Replies)
Discussion started by: OrthoProof USA
3 Replies

3. UNIX for Dummies Questions & Answers

reverse of touch command

If touch command sets the modification and access times of files to the current time of day, is there a command that could do the reverse of this? Say change the access times of files to an earlier time or date? Say I have this file: HOME> ls -l -rw-rw-r-- 1 orbix orbix 886 May... (1 Reply)
Discussion started by: Orbix
1 Replies

4. UNIX for Dummies Questions & Answers

touch command help

Hi, This might be the stupidest question ever but here it goes, i need to create a file with the name Hello! It's $s It using the touch command but whenever i use touch 'Hello! It's $s' i get s is undefined touch Hello! It's $s i get ' unmatched Please help ^_^ (6 Replies)
Discussion started by: wsn
6 Replies

5. UNIX for Dummies Questions & Answers

how to get the timestamp using touch command

Can any one provide answer for the below 3 requirements, 1. file.txt grep "name" file.txt > file1.txt rm -f file.txt mv file1.txt file.txt as per abov, a pattern grepped in file.txt and the content moved to again file.txt My need is i want the timestamp of file.txt before chaning and... (3 Replies)
Discussion started by: prsam
3 Replies

6. UNIX for Dummies Questions & Answers

touch command

Is there a way to do... touch ./config/newdir/newfile if neither newdir and newfile exists? man touch tells me there's not (?) Is out there another tool to do that? Thx in advance! :b: (6 Replies)
Discussion started by: funyotros
6 Replies

7. Shell Programming and Scripting

Issue with touch command

Hi, I have a touch command in my script which creates / updates a file TODAY. Then i try to find the list of files which are newer than this TODAY file. touch `date '+%m%d'`0000 TODAY cd /auto/users-35/p494856/learning/filetransfer/ find . -name "*csv" -newer... (3 Replies)
Discussion started by: arunkumarmc
3 Replies

8. Shell Programming and Scripting

Help on touch command

Hi all I changed some of my files in my hoem directory to old dates using the touch command like this touch -t 200805101024 file name but after using this command the date changed properly but it displays like below -rwxr--r-- 1 fincntrg fingrp 193619 May 10 2008 vi.pdf I... (3 Replies)
Discussion started by: thelakbe
3 Replies

9. UNIX for Dummies Questions & Answers

Using touch command in ftp

hi , I am transferring files from one unix server to another, after transfer of a file i want to touch the same file name in another directory in the destination server. How can i touch a file when i am in ftp prompt on the source server. Thanks in advance (2 Replies)
Discussion started by: nick1982
2 Replies

10. UNIX for Advanced & Expert Users

Help with Touch Command

Hello, I am trying to use touch command to create 1200 .txt files. I am using this, but it is not working. touch `seq 1 1200`.txt Regards, Siddhesh.K (5 Replies)
Discussion started by: Siddheshk
5 Replies
escape(1)                                                       Mail Avenger 0.8.3                                                       escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 02:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy