|
Home > Archive > Unix Shell > December 2007 > unix shell script help (KSH on AIX)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
unix shell script help (KSH on AIX)
|
|
| nmenefee@gmail.com 2007-12-10, 7:20 pm |
| I'm no good at writing shell scripts. Hopefully somebody can help me
flush out my idea, or at least point me in the right direction.
First of all here's what I'm trying to do. Unix flavor is AIX.
I'm trying to write a KSH shell script to run a few commands and save
the ouput to a text file.
Here's the breakdown of what should be in the file
Hostname :
Boxhostname
Processors:
2
Version:
Result of a command
Thats all I need in the file. I'm I figure I can do the first two
things like so.
echo Hostname: >> file.txt
hostname >> file.txt
echo Processors: >> file.txt
lscfg -v | grep -c proc >> file.txt
echo Version: >> file.txt
Now for the third thing it gets a bit harder, Here's the breakdown
1.) Try to run a command
2.) If Successful end
3.) If not found, (not pathed) do a find / -name programname
4.) if nothing found then echo Program not found >> file.txt
5.) if results found try to run first one in the list with options (so
if I searched for program I want to try to run program -o >> file.txt
the other gotcha is I want to name the file.txt file something like
scan_hostname.txt where hostname is the hostname as it appears from
the hostname command. Not all the boxes have the hostname environment
variable set, but the hostname command should return the correct
hostname.
| |
| Barry Margolin 2007-12-11, 1:37 am |
| In article
<d59b1b1a-3520-40b4-85c5-bab81838001f@v4g2000hsf.googlegroups.com>,
"nmenefee@gmail.com" <nmenefee@gmail.com> wrote:
> I'm no good at writing shell scripts. Hopefully somebody can help me
> flush out my idea, or at least point me in the right direction.
> First of all here's what I'm trying to do. Unix flavor is AIX.
>
> I'm trying to write a KSH shell script to run a few commands and save
> the ouput to a text file.
>
> Here's the breakdown of what should be in the file
> Hostname :
> Boxhostname
> Processors:
> 2
> Version:
> Result of a command
>
>
>
>
>
> Thats all I need in the file. I'm I figure I can do the first two
> things like so.
>
> echo Hostname: >> file.txt
> hostname >> file.txt
> echo Processors: >> file.txt
> lscfg -v | grep -c proc >> file.txt
> echo Version: >> file.txt
>
>
>
> Now for the third thing it gets a bit harder, Here's the breakdown
>
> 1.) Try to run a command
> 2.) If Successful end
> 3.) If not found, (not pathed) do a find / -name programname
> 4.) if nothing found then echo Program not found >> file.txt
> 5.) if results found try to run first one in the list with options (so
> if I searched for program I want to try to run program -o >> file.txt
>
>
>
>
> the other gotcha is I want to name the file.txt file something like
> scan_hostname.txt where hostname is the hostname as it appears from
> the hostname command. Not all the boxes have the hostname environment
> variable set, but the hostname command should return the correct
> hostname.
#!/bin/sh
# Redirect all output to file
exec > scan_`hostname`.txt
echo Hostname:
hostname
echo Processors:
lscfg -v | grep -c proc
echo Version:
if ( programname ) 2>/dev/null
then exit
fi
prog=`find / -name programname | head -1`
if [ "$prog" ]
then "$prog" -o
else echo Program not found
fi
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Ed Morton 2007-12-11, 1:24 pm |
| On 12/10/2007 6:34 PM, nmenefee@gmail.com wrote:
<snip>
> Now for the third thing it gets a bit harder, Here's the breakdown
>
> 1.) Try to run a command
> 2.) If Successful end
> 3.) If not found, (not pathed) do a find / -name programname
> 4.) if nothing found then echo Program not found >> file.txt
> 5.) if results found try to run first one in the list with options (so
> if I searched for program I want to try to run program -o >> file.txt
That sounds like an incredibly bad idea. What if the command you're searching
for is "ls" and the first place you find it is in someone's bin where they have
a command called "ls" which contains "cd $HOME; rm -rf *"?
Ed.
| |
| Kenny McCormack 2007-12-11, 7:24 pm |
| In article <475EA519.4000209@lsupcaemnt.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
>On 12/10/2007 6:34 PM, nmenefee@gmail.com wrote:
><snip>
>
>That sounds like an incredibly bad idea. What if the command you're
>searching for is "ls" and the first place you find it is in someone's
>bin where they have a command called "ls" which contains
>"cd $HOME; rm -rf *"?
>
> Ed.
This risk is really overstated. The fear is rooted in tricks done in
the old days in academic environments. Nowadays:
1) In a professional environment, the answer is simple. Figure
out who did and get them fired. End of problem.
2) In an academic environment, first of all, kids these days are
so dumb, they'd never be able to do it, and second, the real
risk is that they are going to video you and post it on youtube.
This kind of techy-pranking just doesn't exist anymore.
|
|
|
|
|