?
Solved

AIX IBM shell commands?

Posted on 2014-01-28
5
Medium Priority
?
761 Views
Last Modified: 2014-01-28
I am doing some research into AIX IBM security, and how to check certain settings. Most of the checks involve you executing commands such as "# ls", "# acl get", "# grep" etc. etc. I assume you run these commands in some equivalent to the windows command shell?
Does it have an option to write the findings out to a text file, as you can in command prompt i..e >filename.txt

And also is there anyway to execute these commands in bulk, i.e. if you had 200 commands,  is there a way to package them alltogether, run the packaged bulk of commands, and have each command write the outout out to a text file, so at the end of the scan all you have got is say 200 text files in the same folder?
0
Comment
Question by:pma111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39814493
You can create a file in your current directory and put all your commands in it, named let's say mycmds, one per line.

You can then simply run this file with

sh mycmds

Output redirection works exactly the same way as in the command prompt. In fact, the command above starts a subshell of your login shell so the behavior of both is the same.

Thus you can append "> unique_logfile_name" to each command in mycmds.

Automating the logfile stuff is also possible, but would involve writing one more shell script, perhaps like this:

#!/bin/ksh
n=1
while read cmd
  do
     eval "$cmd" > ${cmd%%" "*}.$n.out
     ((n+=1))
  done < mycmds

Put the above in a new file in your current directory named e.g. runcmds
then issue "chmod+x runcmds" and run it like this:

./runcmds

${cmd%%" "*}.$n.out constructs an output file name consisting of the first word of the command, a dot, a serial number for uniqueness, and the appendix ".out"

I used "eval" to run the single commands in case you have special things like pipes etc. in them.
0
 
LVL 3

Author Comment

by:pma111
ID: 39814993
Thanks. Do you have to put any form of file extension of the mycmds file, so that the sh command can execute it?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39815005
No, you don't. Unix/Linux shells don't rely on filename extensions.

Name your scripts as you like (to make your life easier choose meaningful names).

You can of course add ".sh" or something similar nonetheless to identify the file as a script at first sight.
0
 
LVL 3

Author Comment

by:pma111
ID: 39815014
wow, thought it would be loads more complex than that. Seems quite painless.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39815017
Yep, it's Unix!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question