A shell script for create a a file in the respective path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A shell script for create a a file in the respective path
# 1  
Old 10-29-2010
A shell script for create a a file in the respective path

Hello forum members,


I have to create a out file in the current path./aaa/bbb/ccc/hhh.
i am writing script below.

###script Begins#####

Code:
#!/bin/ksh
echo "Weclome"
if [ -d $aaa/bbb/ccc/hhh ]
then
        echo "Hello"
        rm -rf $aaa/bbb/ccc/hhh        #clean the exsisting o/p file
        echo "no  dir found"
        mkdir $amex/gcst/siva/final
        echo ""User id" "Password"      " >$aaa/bbb/ccc/hhh/log
fi
echo "OUT"

#### script End#########

O/P
welocm
OUT.
it not entering into the if condition so please suggest me how to correct it to create a log file
I am looking forward from youSmilie

Thanks & Regards
rajkumar G

Last edited by pludi; 10-29-2010 at 08:26 AM.. Reason: code tags, please...
# 2  
Old 10-29-2010
If it's not entering the if statement then the test condition is not true or it is not satisfied. [ -d $aaa/bbb/ccc/hhh ]. Before running the script check if those directories exist and also make sure variable $aaa has got some value.
# 3  
Old 11-01-2010
Quote:
Originally Posted by michaelrozar17
Before running the script check if those directories exist and also make sure variable $aaa has got some value.
Or better, make it a part of your script:

Code:
if [[ -z $aaa ]]
then
   echo "$(date) variable aaa is undefined and must contain a valid directory"
fi
if [[ ! -d $aaa ]]
then
   echo "$(date) variable aaa must contain a valid directory; it does not: $aaa"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Create file from script shell

Hello all :) Here is my code i try to complete: address1="$(ssh root@$machine -x "lxc-info -n $machine-worker1 -H -i")" if //ifthe file addrfile does not exist then create the file addrfile echo "$address1">"$addrfile" fi "$address1">"$addrfile" How, can i... (4 Replies)
Discussion started by: chercheur111
4 Replies

3. UNIX for Dummies Questions & Answers

Download .xls file from mail and copy to another path using shell script

Hi I have a mail attachment coming from a mail id and evreytime with the same name in .xls format.I have to download the .xls file into a location and convert it itno .csv format and copy the .csv file to another location. (1 Reply)
Discussion started by: bikky6
1 Replies

4. UNIX for Dummies Questions & Answers

How to Create excel file(.csv) using shell script?

Hi, i have shell script which compiles n number of test cases and execute them one by one. i want to create report in excel through script in which two columns namely "test id" and "release".second column have two subcolumns namely compiles and excutes. so i want first column should display test... (15 Replies)
Discussion started by: RamMore123
15 Replies

5. Shell Programming and Scripting

Need help to create multiple file using shell script

HI, i created the below script to create the multiple files, iam not getting the required output, Please advice. #!/bin/sh v_date=$1 # argument will come as daymonthyear eg : 151112 v_day=`echo $v_date | cut -c 1-2` v_mon=`echo $v_date | cut -c 3-4` v_year=`echo $v_date | cut -c 5-6`... (4 Replies)
Discussion started by: jagguvarma
4 Replies

6. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

7. Shell Programming and Scripting

Copy respective path next to last column with awk

Hi to all, I have the short print out sample of the DOS command "dir S/" as showed below. Directory of C:\Program Files\Winamp\Skins\Bento\window 02/12/2010 11:35 p.m. <DIR> . 02/12/2010 11:35 p.m. <DIR> .. 11/12/2009 10:31 a.m. 13,556... (3 Replies)
Discussion started by: cgkmal
3 Replies

8. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

9. Shell Programming and Scripting

Shell script to loop for a particular file in predefined path

Hi , i need a shell script to poll a particular file in a predefined directory , once that file is found , i need to launch another shell script . Eg i need to poll for A.txt in /home/username/Desktop once A.txt is created by Desktop(Created by another Script) , i need to launch another... (2 Replies)
Discussion started by: Vinod H C
2 Replies

10. Shell Programming and Scripting

want only file names (not whole path) in shell script

hi i wrote following script, #!/usr/bin/sh for index in `ls /tmp/common/*.txt` do echo "$index" done here index is giving full path but in my program i want only file names (not along with whole path) Eg. if in /tmp/common files are a.txt and b.txt den out should be a.txt b.txt ... (6 Replies)
Discussion started by: crackthehit007
6 Replies
Login or Register to Ask a Question