How to keep track of filename in different shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to keep track of filename in different shell
# 1  
Old 01-17-2009
Java How to keep track of filename in different shell

Guys I am trying to install the pkg using the follwoing script.
Trying to run the script from one machine to other machines with the follwoing code.

Now my problem is, when I use scp command on the remote machine, how do i keep track of filename in some variable or that sort of thing.

Below is the sample code.

for GETHOST in `cat $FILENAME`
do
echo "\n Logging onto $GETHOST"
ssh $GETHOST <<EOT
#Getting the machine info for Sparc / AMD machine
TYPE=`uname -a | awk '{print $6}'`
if [ $TYPE != sparc ];
then
scp beast:$AMD_DIR/*.pkg.tar.gz $GETHOST:/home/somename/pkg/
if [ $? = 0 ];
then
echo " Copied the file(s) Successfully on $GETHOST from beast"
else
echo " File(s) not copied on $GETHOST from beast"
exit 2
fi

[Here I have to keep track of all the recent files that have been scp'ed]or suggest any other alternative or any other condition please]
else
scp beast:SPARC_DIR/*.pkg.tar.gz $GETHOST:/home/somenam/pkg/
if [ $? = 0 ];
then
echo " Copied the file(s) Successfully on $GETHOST from beast"
else
echo " File(s) not copied on $GETHOST from beast"
exit 2

[SAME LIKE ABOVE - Here I have to keep track of all the recent files that have been scp'ed]or suggest any other alternative or any other condition please]
fi
fi
# Better to check once again if scp is successfull

# End of here document
EOT
# End of main for loop
done
# 2  
Old 01-17-2009
Don't know how tab spaces converted into plain text.
please tab by yourself on the If conditions for more clarity....
# 3  
Old 01-17-2009
Quote:
Originally Posted by sdosanjh
Now my problem is, when I use scp command on the remote machine, how do i keep track of filename in some variable or that sort of thing.

filelist="$filelist
NEXTFILE"
Quote:
Below is the sample code.

Please put code inside [code] tags.
Quote:
Code:
for GETHOST in `cat $FILENAME`


While it probably doesn't matter in this case, that is almost always the wrong way to read a file. Use a while loop:

Code:
while read GETHOST
do
   TYPE=$(ssh "$GETHOST" uname -m)
   case $TYPE in
      sparc) sourcedir=SPARC_DIR ;;
      *) sourcedir=$AMD_DIR ;;
   esac
   scp beast:"$sourcedir"/*.pkg.tar.gz "$GETHOST":/home/somename/pkg/ > LOGFILE &&
    echo " Copied the file(s) Successfully on $GETHOST from beast" || {
    echo " File(s) not copied on $GETHOST from beast"
    exit 2
   }
done < "$FILENAME"

# 4  
Old 01-18-2009
Quote:
Originally Posted by cfajohnson

filelist="$filelist
NEXTFILE"

Please put code inside [code] tags.

While it probably doesn't matter in this case, that is almost always the wrong way to read a file. Use a while loop:

Code:
while read GETHOST
do
   TYPE=$(ssh "$GETHOST" uname -m)
   case $TYPE in
      sparc) sourcedir=SPARC_DIR ;;
      *) sourcedir=$AMD_DIR ;;
   esac
   scp beast:"$sourcedir"/*.pkg.tar.gz "$GETHOST":/home/somename/pkg/ > LOGFILE &&
    echo " Copied the file(s) Successfully on $GETHOST from beast" || {
    echo " File(s) not copied on $GETHOST from beast"
    exit 2
   }
done < "$FILENAME"







thanks dude...code looks good...but my issue is.... after scp i want to run the pkginstall commands with each filename i scp'ed ... since i am in different shell. isn't it difficult to track the filename of AMD / SPARC directories???? so any alternative to get the file name scp'ed and then use it for pkginstall command...
# 5  
Old 01-19-2009

You have the names in LOGFILE.
# 6  
Old 01-19-2009
Thanks john.... it was skipped from my eyes....yeah we can take from LOGFILE.....
Cheers and thanks for the help. will come again on this forum if stuck with some issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch the latest filename shell script

Hi I want to fetch the latest file form the list example example= filename RATE_STATE_SETUPS.20151222.ccyymmdd.hhmmss.txt File pick which have latest ccyymmdd.hhmmss list of file in directory are RATE_STATE_SETUPS.20151222.20151222.170101.txt... (5 Replies)
Discussion started by: MOHANP12
5 Replies

2. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

3. Shell Programming and Scripting

Help shell script to list filename file_path

HI owner date and time and size of file in a row shell script to list filename file_path i have tried the below code present_dir=`pwd` dir=`dirname $0` list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` size=`du -h` path=`cd $dir;pwd;` printf "$list" printf "$path" printf " $size" ... (4 Replies)
Discussion started by: abiram
4 Replies

4. Shell Programming and Scripting

Shell script if [[ -L <filename> ]]

Hi Please describe about following condition if ] in shell script. Also please provide the link related all the flags which are applicable for if condition in Shell (4 Replies)
Discussion started by: munna_dude
4 Replies

5. Shell Programming and Scripting

Which shell script will call if i execute sh (without filename)?

Hi Friends, The below shell script is written by third party to create B2k_session_id.iam trying to execute this script.When i execute below script it is calling some other scripts.How to find which scripts is calling? . `execom commfunc.com` echo " $PRESENTATION_MODE " if then echo... (1 Reply)
Discussion started by: vadlamudy
1 Replies

6. Shell Programming and Scripting

Using sed '${linenum}d' $filename in shell

Hi Experts, Please let me know how to below situation: Looking for: sed "${linenum}d" $filename > $filename _Without_7C Working Command: sed "${linenum}d" A020820122200.tis2webGMNA001_GDS_DIDOut.txt > A020820122200.tis2webGMNA001_GDS_DIDOut.txt_Without_7C appriciate if you can... (7 Replies)
Discussion started by: rajubollas
7 Replies

7. Shell Programming and Scripting

Korn Shell & Nawk...Filename changes

I have the following piece of code: YESTER=`TZ=aaa24 date +%b"-"%d` filelist2=$(find /export/home/gen/check/logs \( -name \*$YESTER\* ! -name \*ADM\* \) -print | tr '\n' ' ') nawk -F':' ' $2 ~ /Reason/ && $3 !~ /(PASSTHRU|OCAP|FP Power Button|Bootloader Reset)/ { split(FILENAME,... (2 Replies)
Discussion started by: ther2000
2 Replies

8. Shell Programming and Scripting

Shell script to use the last modified filename in a variable

Forgive me if this is a trivial question, but I haven't been able to find the answer to this. Basically I've got a list of files in a particular directory that have the general form t_*.dat. (I have other files in the same directory as well). Essentially what I want to do is obtain the name... (1 Reply)
Discussion started by: lost.identity
1 Replies

9. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies

10. Shell Programming and Scripting

sed / shell - how to use $filename

I've forgotten how to use a filename parameter using sed inside a shell script. What I want to do is replace a string inside a file with the name of the file being processed. I think this should work .. for filename do sed -e "s/xxx/$filename/" ... ... done Thanks! Ps: ... (5 Replies)
Discussion started by: eadie
5 Replies
Login or Register to Ask a Question