The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reading ,writing,appending ,manipulating a file. szchmaltz UNIX for Dummies Questions & Answers 4 06-17-2008 02:02 AM
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
reading/ writing to sockets rein Shell Programming and Scripting 1 09-20-2007 08:57 PM
Reading and Writing file on LAN lucky001 High Level Programming 3 03-30-2007 02:16 PM
Reading and Writing Files ? tracydp UNIX for Dummies Questions & Answers 3 08-30-2006 10:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Log File Writing and Reading

Hi all,
I have the following shell script code which tries to sftp and writes the log into the log file.

Code:
TestConnection ()
{
  echo 'Connection to ' $DESTUSERNAME@$DESTHOSTNAME
  $SETDEBUG
  if [[ -a $SCRIPT ]]; then rm $SCRIPT ; fi
  touch $SCRIPT
  echo "cd" $REMOTEDIR >> $SCRIPT
  echo "quit" >> $SCRIPT
  
  chmod 700 $SCRIPT
  sftp -b $SCRIPT $DESTUSERNAME@$DESTHOSTNAME > $SESSIONLOG
  
  echo '**** FTP log reproduced below:'
  echo '-----------------------------------------------------------'
  cat $SESSIONLOG
  echo '-----------------------------------------------------------'
}
the code executes well and when i manually vi the log file i can see some data written into it...

Whereas the portion of script(cat $SESSIONLOG) does nothing.It prints nothing.Does anyone know what could be the problem?.

I am new to unix and iam thinking is it because iam trying to cat from a file which might be still Open?If yes how do i get around it?

Please help.

Regards
  #2 (permalink)  
Old 11-25-2008
mk1216 mk1216 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Bristol , United Kingdom
Posts: 38
try "echo $SESSIONLOG" before "cat" command and see if the variable has a proper value .
  #3 (permalink)  
Old 11-25-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
If $SESSIONLOG was empty or had nonsense inside, cat would tell something like "file not found".
You should also write stderr out to your log like:
Code:
sftp -b $SCRIPT $DESTUSERNAME@$DESTHOSTNAME > $SESSIONLOG 2>&1
If it is still empty, maybe put a -v for verboste to the sftp.
  #4 (permalink)  
Old 11-25-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Quote:
Originally Posted by zaxxon View Post
If $SESSIONLOG was empty or had nonsense inside, cat would tell something like "file not found".
You should also write stderr out to your log like:
Code:
sftp -b $SCRIPT $DESTUSERNAME@$DESTHOSTNAME > $SESSIONLOG 2>&1
If it is still empty, maybe put a -v for verboste to the sftp.

Thats correct Zaxxon.
Adding
sftp -b $SCRIPT $DESTUSERNAME@$DESTHOSTNAME > $SESSIONLOG 2>&1
did the trick....thanks a lot guys
  #5 (permalink)  
Old 11-25-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
One more question:

I want to compare the value of the variable against a string and i am using the below code,but doe's'nt seem to do it...is there anything wrong with it??

Code:
if echo "$PRECHECK" | grep 'FALSE'; 
    then
      echo "File Ftped Successfully: " $f
      mv $f "FTPED_"$f
    fi

Thanks
  #6 (permalink)  
Old 11-25-2008
mk1216 mk1216 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Bristol , United Kingdom
Posts: 38
if [ ! -z $PRECHECK ] && [ $PRECHECK == "FALSE" ]
then
echo "File Ftped Successfully: " $f
mv $f "FTPED_"$f
fi
  #7 (permalink)  
Old 11-25-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Quote:
Originally Posted by mk1216 View Post
if [ ! -z $PRECHECK ] && [ $PRECHECK == "FALSE" ]
then
echo "File Ftped Successfully: " $f
mv $f "FTPED_"$f
fi
Thank you very much.It worked...
I assume [ ! -z $PRECHECK ] means does the variable precheck exist??

One more thing is that I need to email the file log contents to a user.
I am using the code below:

Code:
cat $SESSIONLOG|mailx -s "Alert created on $DATERUN : Transaction date is $DATERUN : Interface failure from RCUK to BottomLine " $EMAILADD
Is it correct? I don't seem to get any emails....
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0