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
Sorting Directory Listing Sepia UNIX for Dummies Questions & Answers 1 07-11-2007 07:44 AM
How can i get directory listing? haisubbu UNIX for Dummies Questions & Answers 2 08-25-2006 09:03 AM
Full Directory Listing... B14speedfreak UNIX for Dummies Questions & Answers 5 05-11-2006 08:06 AM
Timestamp in directory listing vijashok UNIX for Dummies Questions & Answers 2 10-06-2005 10:03 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 10:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-08-2008
grebbux grebbux is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 10
nicely formatted directory listing from batch ssh session

Hi,

I am really struggling to finish of a script I have been assigned.
The script's purpose is to log on to each server defined in an array, determine the Web Server version, and list the directory beneath the installation directory. In my case, this installation directory is almost always "/opt/IBMHTTPServer" (sometimes "/opt/IBMHttpServer")

Here's a snippet from the code.

Code:
for host in ${Hosts}
do
  AssumedDir=$(batch_ssh ${host} "ls -1 /opt")
  if [[ ${AssumedDir} = *IBMHTTPServer*  ]]; then
    ServerInstallDir='/opt/IBMHTTPServer'
  else
    ServerInstallDir='/opt/IBMHttpServer'
  fi

 #DirectoryListing=$(batch_ssh ${host} "find ${ServerInstallDir} -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'")
 #DirectoryListing=$(batch_ssh ${host} "ls -1 $ServerInstallDir")
 DirectoryListing=$(batch_ssh ${host} "ls -1 $ServerInstallDir | while read d; do echo $d ; done")

  ServerVersion=$(batch_ssh ${host} "${ServerInstallDir}/bin/httpd -V | awk 'NR < 2'")

  echo '<br /><h3>'${host}'</h3>' >> $HTMLFILE
  echo '<b>Server Version</b>: ' ${ServerVersion} >> $HTMLFILE
  echo '<br /><b>Directory Structure</b><br /> ' $DirectoryListing >> $HTMLFILE

done

#- Email results
html_mail -t "some.body@company.co.uk" -r "noreply@servername" -s "Apache Security Audit" -a "$HTMLFILE"
(That sed command above come from a UNIX forums frequent, i forget the name! Thanks though - the two commented DirectoryListing vars are just experimentation)

So after this script has done it's thing, it invokes a perl script (html_mail) to send the report. (I didn't make this, and I know it works well). The mail comes through as planned, however the directory listing is very ugly, it looks like this:

Code:
_uninst admindocs bin cgi-bin conf example_module htdocs icons include keys.q.hpicheck.com keys.q.hpicheck.com.20061002_141729 keys.q.racexaminations.co.uk keys.q.racvehiclehealthcheck.co.uk keys.q.vehiclestatusreport.co.uk libexec license logs man readme ssl tivready version.signature
I would like the above files/directory's to be listed like they would be after issuing `ls -1` from the shell.

Thank you for reading my post, I hope someone can help me. If you have any comments of the quality of the code above please air them, as it is my first (somewhat) useful script, and I'm eager for all the feedback I can get. (Full version of the script is Bash pastebin - collaborative debugging tool)

Thank you.
  #2 (permalink)  
Old 03-08-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try adding double quotes:
echo '<br /><b>Directory Structure</b><br /> ' "$DirectoryListing" >> $HTMLFILE
  #3 (permalink)  
Old 03-09-2008
grebbux grebbux is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 10
Thanks for the reply, Perderabo.

When I do as you suggest, no output returns for the directory structure listing.

I tried my other two experimental "DirectoryListing" variables with the variable "double quoted" in the echo statement, that gives output, but the same, ugly, output I was having before.

Thanks,
grebbux.
  #4 (permalink)  
Old 03-09-2008
grebbux grebbux is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 10
I think I'm getting somewhere, when I try this:

Code:
echo $DirectoryListing | sed 's/ /<br>/' >> $HTMLFILE
FYI: Nothing is listed if I put the above $DirectoryListing in "".

The listing looks like this:

Code:
_uninst
admindocs bin cgi-bin conf example_module htdocs icons include keys.q.hpicheck.com keys.q.hpicheck.com.20061002_141729 keys.q.racexaminations.co.uk keys.q.racvehiclehealthcheck.co.uk keys.q.vehiclestatusreport.co.uk libexec license logs man readme ssl tivready version.signature
So I have one <br> after the first listing. I don't understand why the break isn't substituted for all the other spaces though!

Thanks again for reading.
grebbux.
  #5 (permalink)  
Old 03-09-2008
grebbux grebbux is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 10
I did it.

I went for the array approach.

Code:
declare -a DirectoryListing
$DirectoryListing=$(batch_ssh ${host} "ls -1 ${ServerInstallDir}")
for dir in ${DirectoryListing[@]}
do
echo $dir '<br>' >> $HTMLFILE
done
Thanks for the help anyway.

***SOLVED***

grebbux.
  #6 (permalink)  
Old 03-09-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally Posted by grebbux View Post
I think I'm getting somewhere, when I try this:

Code:
echo $DirectoryListing | sed 's/ /<br>/' >> $HTMLFILE
So I have one <br> after the first listing. I don't understand why the break isn't substituted for all the other spaces though!
That sed s command only replaces the first match. You need the g flag to do them all.

Code:
echo $DirectoryListing | sed 's/ /<br>/g' >> $HTMLFILE
But I'm glad you got it solved.
  #7 (permalink)  
Old 03-09-2008
grebbux grebbux is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 10
Ah thanks for answer there, I think the sed substitution is a better solution.
Sponsored Links
Closed Thread

Bookmarks

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 03:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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