- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to list commands and their output in different...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 10:44 AM
06-06-2008 10:44 AM
Now, I want to write a script, then have outputs to list each one of commands itself and following it's corresponding output. Each command and it's output should start with different page.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 10:57 AM
06-06-2008 10:57 AM
Re: how to list commands and their output in different pages.
#!/usr/bin/sh
exec >> /tmp/mylog
CMD="cat /etc/hosts"
echo ${CMD}
eval ${CMD}
echo "\015"
# etc...
...prn [repeat as necessary]...
Notice that the redirection is done once for the duration of your script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:02 AM
06-06-2008 11:02 AM
Re: how to list commands and their output in different pages.
Do you mean print on a printer on different page?
Something like
while read a
do
banner "$a"
$a
echo ^L # type ctrl V ctrl L
done <
cat /tmp/toto
ps
echo yes
EOF
Sometimes generate in html it gives some nice outputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:03 AM
06-06-2008 11:03 AM
Re: how to list commands and their output in different pages.
exec >> /tmp/mylog
CMD="cat /etc/hosts"
echo ${CMD}
eval ${CMD}
echo "\015"
# etc...
Okay. Understand...
but, how would you put all different commands, for instance, cat /etc/hosts, cat /etc/passwd,....in a loop, and assign each command to CMD?
Thanks...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:09 AM
06-06-2008 11:09 AM
Solution#!/usr/bin/sh
exec > mylog
while read CMD
do
echo "${CMD}"
eval "${CMD}"
echo "\015"
done < mycmds
...where 'mycmds' simply looks like:
# cat mycmds
cat /etc/hosts
cat /etc/services
vgdisplay
date
...notice the double quotes in the script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:22 AM
06-06-2008 11:22 AM
Re: how to list commands and their output in different pages.
echo "\015" seems only separate each command and it's output by one empty line, how do I separate them by starting a new page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:32 AM
06-06-2008 11:32 AM
Re: how to list commands and their output in different pages.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:39 AM
06-06-2008 11:39 AM
Re: how to list commands and their output in different pages.
in between each group of outputs...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:40 AM
06-06-2008 11:40 AM
Re: how to list commands and their output in different pages.
> Hein: try \014 for "Form Feed" instead of \015 for "Carriage Return
Yes, indeed! Thanks my friend.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:44 AM
06-06-2008 11:44 AM
Re: how to list commands and their output in different pages.
Does that work?
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:51 AM
06-06-2008 11:51 AM
Re: how to list commands and their output in different pages.
Yes, a ^L when viewed with 'vi' (for example) is indeed a formfeed (\014). If you send the generated file to a printer, it will be honored as such. Using a pager like 'more' to view the file at your terminal will not interpret the character either. A 'cat' of the file would, but that would be a bit useless.
I think you would be better served by injecting a line of dashes to separate each command and its output. That way the output file could be viewed on a terminal as well as printed.
In fact, if you wanted to print the file, simply use 'sed' to change the dashes to true form feeds:
# sed s'/^------/\^L/' file | lp
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 11:54 AM
06-06-2008 11:54 AM
Re: how to list commands and their output in different pages.
echo "\012" will give you 2 empty lines in between.
Just want to make sure, I am not going to print out the entire output, just into a unix file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:13 PM
06-06-2008 12:13 PM
Re: how to list commands and their output in different pages.
echo "" | awk '{print "\f"}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:21 PM
06-06-2008 12:21 PM
Re: how to list commands and their output in different pages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:22 PM
06-06-2008 12:22 PM
Re: how to list commands and their output in different pages.
Hanry, re-read my last offering.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:42 PM
06-06-2008 12:42 PM
Re: how to list commands and their output in different pages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:42 PM
06-06-2008 12:42 PM
Re: how to list commands and their output in different pages.
> start with different page.
That's "its". A "different page" on what?
Ctrl/L = 12 (dec) = 0xC (hex) = 014 (octal) =
Form Feed, which is ASCII for "go to the next
page".
> I am not going to print out the entire
> output, just into a unix file.
Define "different page" in "a unix file".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 12:59 PM
06-06-2008 12:59 PM
Re: how to list commands and their output in different pages.
page 1:
command1
command1 output
page 2:
command2
command2 output
....
page n:
commandn
commandn output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 01:07 PM
06-06-2008 01:07 PM
Re: how to list commands and their output in different pages.
while read a
do
echo $a
$a
echo "\014" # or ^L
done <
ps
echo yes
EOF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 01:48 PM
06-06-2008 01:48 PM
Re: how to list commands and their output in different pages.
so, echo "\014" only works when you combine with "pr" command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 02:23 PM
06-06-2008 02:23 PM
Re: how to list commands and their output in different pages.
The problem is, as Steven to clearly points out, the defintion of 'a page'.
This sounds simple and intuitive, but it is not.
IF you are sending a file to a printer THEN a FormFeed character, aka FF, aka ^L, aka \014 will instruct most (all?) printers to skip to the next page.
Some online programs will honor this in an emulated fashion.
'cat' does not... it just sends it through so then it depends on your terminal (emulator) settings what happens.
Typically it skips to a clean page, making it pointless.
hpux 'more' donly displays a replacement "^L".
Linux 'more' which typically is 'less' does more.
It does it 'correctly' pausing after each 'page'.
Try to get a 'less' for hpux.
Your best bet IMHO is to inject a good few new-lines and a recognizable pagebreak indicator.
Untested: echo "\n\n\n\n--- $CMD ---\n\n"
hth,
Hein.