- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to assign a variable containing other variable...
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
04-07-2007 04:30 AM
04-07-2007 04:30 AM
how can assign the value to the variable named "LOG"
LOG=$($log/$(echo $0 | cut -d"/" -f5 | cut -d"." -f1))
if i run above, there is an error:
$ 01_bdf_filesystem.sh
01_bdf_filesystem.sh[28]: /home/MONITOR/LOG/01_bdf_filesystem: cannot execute
esto vale log:
please let me knnow.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2007 04:33 AM
04-07-2007 04:33 AM
Re: How to assign a variable containing other variables
Name of the script: 01_bdf_filesystem.sh
. $HOME/ENVIRONMENT/environment.sh
typeset -i b=0 u=$1
LOG=$($log/$(echo $0 | cut -d"/" -f5 | cut -d"." -f1))
echo esto vale log: $LOG
read jkjkjk
for a in `bdf | grep vg0 | awk '{ print $5"_"$6}'`
do
if [[ $a != "_" ]]
then
b=`echo $a | cut -d"%" -f1`
if [[ $b -gt $u ]]
then
c=`echo $a | cut -d"_" -f2`
#echo $c ${b}% >> $log/`echo $0 cut -d"." -f1`/filesystem_high_$hour
echo $c ${b}% >> ${LOG}/filesystem_high_$hour
zz=1
mailx -s "WARNING on $(hostname) - Filesystem size higher than ${1}%" $emails_dma < ${log}/filesystem_hight_$hour
echo "FS size > ${1}%" | mailx -s "WARNING on $(hostname) - " $cellulars_dma
fi
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2007 04:37 AM
04-07-2007 04:37 AM
Re: How to assign a variable containing other variables
I know what is the problem:
LOG=$($log/$(echo $0 | cut -d"/" -f5 | cut -d"." -f1))
i have to writte the following:
LOG="$log/$(echo $0 | cut -d"/" -f5 | cut -d"." -f1)"
Thanks anyway ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2007 04:51 AM
04-07-2007 04:51 AM
SolutionThat manual parsing of the scrip name is just horrible.
Very inflexible. What if the script is supposed to have a . in the middle of the name?
What if you stick in one directory level deeper or less deep?
Please consider using 'basename'
for example:
LOG="$log/$(basename $0 .sh)
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2007 05:08 AM
04-07-2007 05:08 AM
Re: How to assign a variable containing other variables
more free advice....
1) you don't need those double quotes to build $LOG.
They don't hurt, but is help you in the long run to know when they are needed, when not. By not having them you can not accidently get them out of balance as i did by (cut & paste) accident in the earlier reply
2) be sure to check out the shell build-ins for variable parsing. In this case consider:
NAME=${0##*/}
STRIPPED=${NAME%.*}
echo "name:$NAME stripped:$STRIPPED"
3) Google: basename +site:itrc.hp.com
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2007 06:34 AM
04-07-2007 06:34 AM
Re: How to assign a variable containing other variables
As Hein noted, consider either using 'basename' and 'dirname' or use the Posix shell's pattern substitution.
Have a look at the manpages for 'basename(1)' [which encompases a discussion of 'dirname(1) too]:
http://docs.hp.com/en/B2355-60105/basename.1.html
Notice that there is an optional 'suffix' argument to 'basename' which allows you to return only the basename without any "extension". For example:
# F=/path/abc.sh
# echo `dirname ${F}`
/path
# echo `basename ${F}`
abc.sh
# echo `basenane ${F} .sh`
abc
Having the ability to snip off the basename without an extension is useful for manipulating related files as in a directory of "*.c" and "*.o" files for example.
For speed, you can often use the shell build-in parameter substitution:
${parameter#pattern}
${parameter##pattern}
${parameter%pattern}
${parameter%%pattern
This is described under "Parameter Substitution" in the 'sh-posix(1)' manpages:
http://docs.hp.com/en/B2355-60105/sh-posix.1.html
# F=/path/to/name;echo ${F%/*}
/path/to
# F=/path/to/name;echo ${F##*/}
name
Regards!
...JRF...