Sponsored Content
Top Forums UNIX for Dummies Questions & Answers nicely formatted directory listing from batch ssh session Post 302173867 by grebbux on Saturday 8th of March 2008 02:06:05 PM
Old 03-08-2008
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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

2. UNIX for Dummies Questions & Answers

SSH Batch configuration

Team, I am trying to do ssh batch as root. I have ssh set-up to do work w/o requiring password/uid on remotes. The problem is I need to submit batch work to remote systems, and NOT have my terminal program.sh lock/wait for the response from remote. This is so I can submit batch work to other... (2 Replies)
Discussion started by: xcom007
2 Replies

3. Shell Programming and Scripting

scripting an ssh session?

I know the root login/password for a machines, and I want to automate some commands like this from each: ssh root@remoteHost1 "tail /var/log/messages" ssh root@remoteHost2 "tail /var/log/messages" ssh root@remoteHost3 "tail /var/log/messages" ssh root@remoteHost4 "tail /var/log/messages" ssh... (2 Replies)
Discussion started by: jjinno
2 Replies

4. Solaris

mbx_bad_handle during ssh -X session

We have a Solaris 10 server that we're migrating an old Cadre Teamwork application to. We find that when users on Sun workstations use ssh -X <username>@<new server> and run Teamwork on this new server it is fine. When cygwin users and linux users run ssh -X to get to this new platform they... (0 Replies)
Discussion started by: pzxkys
0 Replies

5. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

6. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

7. Shell Programming and Scripting

SSH session saving

Hi, I want to execute some script on the remote session and transfer the processed file on remote machine to local machine. I tried with ssh-keygen and ssh-copy-id but seems that this has been disable on the remote machines, Is there any possiblity that I can save the remote username and... (7 Replies)
Discussion started by: maruthavanan
7 Replies

8. UNIX for Dummies Questions & Answers

SSH session

I ran a job using SSH and then used screen command followed by space bar. Then I ran the job. But after some hours, the internet connection was lost.This had happened to me before. I used to run the whole job again. Today I came across the fact that I could restart the jobs without having to do it... (2 Replies)
Discussion started by: nellierd
2 Replies

9. UNIX for Dummies Questions & Answers

SSH batch help

Dear Gurus, I had hundreds of equipments which i can only use SSH to login and retrieve informations. Thus, how should i do that? eg:ssh batch @ echo off ssh <server1>@10.168.1.1 ECHO testing1 exit ssh <server2>@10.168.1.2 ECHO testing2 exit Can the above method used? :) (6 Replies)
Discussion started by: ymeyaw
6 Replies

10. UNIX for Advanced & Expert Users

Formatted Directory Listing Question

Greetings to you. I have a quick question for the community today ;) I'm interested in the following format for recursive output from a command such as "ls" or "dir" when pointed to a folder: ...but there doesn't seem to be coverage for this type of output formatting in the manpages. Maybe... (11 Replies)
Discussion started by: LinQ
11 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 11:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy