- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Qualifying variables across files
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
Discussions
Discussions
Forums
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
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
тАО10-10-2007 11:04 PM
тАО10-10-2007 11:04 PM
Server1:/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/logs/dmgr/SystemOut.log
Server2:/opt/IBM/WebSphere/AppServer/profiles/Dmgr02/logs/dmgr/SystemOut.log
Server3:/opt/IBM/WebSphere/AppServer/profiles/Dmgr03/logs/dmgr/SystemOut.log
I have more than one file on each server, but for the purposes of this I'll keep it simple.
I have a reference file with a list of logs, and I've sumplimented the Dmgr0n with a variable $DMGR. I then have a script that should substitute $DMGR with the actual name, then role the logs.
The script:
~~~~~~~~~~~~~~~~~~~~~~~~
DATE=`date +%b%o`
WASLOGS=/sysadmin/unix/scripts/puma/WASlogs
HOST=$1
case $1 in
Server1)
DMGR=Dmgr01
;;
Server2)
DMGR=Dmgr02
;;
Server3)
DMGR=Dmgr03
;;
esac
echo $DMGR
for FILE in `cat $WASLOGS`
do
echo $FILE
if [ -f $FILE ]
then
OLDFILE=$FILE.$DATE
mv $FILE $OLDFILE 2>&1
> $FILE
fi
done
~~~~~~~~~~~~~~~~~~~~~~~~
The referenced file contains: /opt/IBM/WebSphere/AppServer/profiles/$DMGR/logs/dmgr/SystemOut.log
The script, when run doesn't recognise the $DMGR in the reference file as a variable, it translates it as a string.
root@Server1:/sysadmin/unix/scripts > ./rolewaslogs.sh Server1
+ + date +%b%o
DATE=Oct07
+ WASLOGS=/sysadmin/unix/scripts/WASlogs
+ HOST=Server1
+ DMGR=Dmgr01
+ echo Dmgr01
Dmgr01
+ cat /sysadmin/unix/scripts/WASlogs
+ [ -f /opt/IBM/WebSphere/AppServer/profiles/$DMGR/logs/dmgr/SystemOut.log ]
Can anyone explain how i can get my script to qualify the variables I'm trying to set in the reference file?
Thanks
Solved! Go to Solution.
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2007 11:30 PM
тАО10-10-2007 11:30 PM
Re: Qualifying variables across files
you could also grep the $WASLOGS file like this:
for FILE in $(grep ${DMGR} $WASLOGS)
then you get only the files which contains $DMGR
hope this helps
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2007 11:33 PM
тАО10-10-2007 11:33 PM
Re: Qualifying variables across files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2007 11:44 PM
тАО10-10-2007 11:44 PM
Re: Qualifying variables across files
you can source the WASLOGS file and redirect it like this:
....
echo $DMGR
#this will "translate" the ${DMGR} variable in the file
. $WASLOGS >> newlogfile #dot space $WASLOGS
for FILE in `cat newlogfile`
....
and another thing write the DMGR variable in the WASLOGS file like this ${DMGR} instead of $DMGR
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2007 12:06 AM
тАО10-11-2007 12:06 AM
SolutionYou need to use 'eval' to cause the parameter substitution:
#!/usr/bin/sh
DMGR=server01
for FILE in `cat WASLOGS`
do
WHICH=$(eval echo ${FILE})
echo ${WHICH}
if [ -f "${WHICH}" ]; then
echo "ok"
else
echo "no file"
fi
done
Regards!
...JRF...
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2007 12:08 AM
тАО10-11-2007 12:08 AM
Re: Qualifying variables across files
I've tried that:
echo $DMGR
. ${WASLOGS} >> newlog
echo ${DMGR}
for FILE in `cat newlog`
do
if [ -f ${FILE} ]
then
OLDFILE=${FILE}.${DATE}
mv ${FILE} ${OLDFILE} 2>&1
> ${FILE}
fi
done
root@hostname:/sysadmin/unix/scripts > cat WASlogs
/opt/IBM/WebSphere/AppServer/profiles/${DMGR}/logs/dmgr/SystemOut.log
It seems to qualify the variable, but gives the following error:
+ . /sysadmin/unix/scripts/WASlogs
+ 1>> newlog
+ /opt/IBM/WebSphere/AppServer/profiles/Dmgr01/logs/dmgr/SystemOut.log
./rolewaslogs.sh[35]: /opt/IBM/WebSphere/AppServer/profiles/Dmgr01/logs/dmgr/SystemOut.log: Execute permission denied.
+ echo Dmgr01
Dmgr01
+ cat newlog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2007 12:14 AM
тАО10-11-2007 12:14 AM