- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell help - How to include prefix information...
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
12-17-2004 12:43 AM
12-17-2004 12:43 AM
I want a general purpose command that either prefixes or appends information when displaying or copying data.
For example:
ndname=`/usr/bin/uname -n`
Output:
server1:root:*:...
server1:adm:*:...
...
where server1 is the host name and the remaining data is info returned from cat /etc/passwd.
server1 prefixes every record.
Thanks... Jack...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2004 12:51 AM
12-17-2004 12:51 AM
Re: shell help - How to include prefix information when copying data
PREFIX="$(hostname)_$(logname)_"
$PREFIX whould yieled "host1_joeblow_" which could be used in file naming i.e.:
OUTFILE="${PREFIX}file1" which would expand to host1_joeblow_file1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2004 12:56 AM
12-17-2004 12:56 AM
Re: shell help - How to include prefix information when copying data
cat /etc/passwd | while read LINE
do
.. echo $ndname ":" $LINE
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2004 01:11 AM
12-17-2004 01:11 AM
Re: shell help - How to include prefix information when copying data
Reason for the script is to be able to consolidate sulogs, sudo logs, lastb output from mulitple servers into a single file so that one file can be examined rather than many.
Examples:
plogger is the script name that contains the capability.
# plogger -p "server1:sulog:" /var/adm/sulog
or
# cat /var/adm/sulog | plogger -p "server1:sulog:" > /tmp/sulog_with_prefix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2004 03:01 AM
12-17-2004 03:01 AM
Solution#!/usr/bin/ksh
file=""
cmd=""
preText=""
preCmd=""
postText=""
postCmd=""
for i in $@
do
case "$i" in
"-preText")
shift;preText="$1"
;;
"-postText")
shift;postText="$1"
;;
"-preCmd")
#just take first line of command output
# i.e. don't want multi line command
###
# might want to do some checking on what the command is
# might not want to run just anything
###
shift;preCmd=$($1 | awk '{print $0;exit;}')
;;
"-postCmd")
shift;postCmd=$($1 | awk '{print $0;exit;}')
;;
"-f"|"-file")
shift;file="$1"
;;
"-c"|"-cmd")
shift;cmd="$1"
;;
*) print "your error message";exit 1;;
esac
done
# do some error checking
# -z $file && -z $cmd
# -n $file && -n $cmd
# etc
###
# you'll need to do want you want
# about weather preText comes before preCmd
# or what order
###
if [[ -n $file ]] ;then
cat $file |
while read line
do
print "${preText}${preCmd}${line}${postCmd}${postText}"
done
else
$cmd |
while read line
do
print "${preText}${preCmd}${line}${postCmd}${postText}"
done
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2004 03:33 AM
12-17-2004 03:33 AM
Re: shell help - How to include prefix information when copying data
#!/bin/sh
######################################################################
# Execution :
# logcon
#
# Requirement :
# Remote login enablement with r* commands
######################################################################
PATH=$PATH:/usr/bin/:/usr/sbin/:/bin/:/sbin/:./usr/local/bin/
if [[ $# -ne 0 ]]
then
echo "
exit 1
fi
host=$1
basename=$(basename $2)
filename=$2
rcp $host:$filename /tmp/$basename_$host.tmp
if [[ -f /tmp/$filename_$host ]]
then
while read line; do
echo "$host:$basename # $line"
done < /tmp/$filename_$host.tmp > /tmp/$basename_$host_$(date +"%d-%m-%y")
fi
# Remove temporary file
rm -f /tmp/$filename_$host.tmp
# Normal exit
exit 0
If you are interested in r* commands(remsh,rcp without passwd login into server).
HTH.