- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Using a file with messages and using in the messag...
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
тАО12-29-2005 09:19 AM
тАО12-29-2005 09:19 AM
i have a file where there are messages:
001#$(date) This is message one with $valor files
002#$(date) There are $v files on $v path
...
...
...
in other file i obtain the message, it depends the case:
one=`cat messages.txt | grep 001 | cut -d"#" -f2`
i invoke a function named hola
hola $one
function hola contains:
echo $1
and the result is:
$(date) This is message one
and it mus be:
Thu Dec 29 16:17:06 MET 2005 This is a message one with 300 files.
Why it can not shown date?
Thanks, Manuales.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2005 09:37 AM
тАО12-29-2005 09:37 AM
SolutionYou need to use 'eval' :
#!/usr/bin/sh
one=`cat messages.txt | grep 001 | cut -d"#" -f2`
valor=13
function hola
{
eval echo $@ #...note!
}
hola $one
exit 0
Notice that instead of $1 I used $@ since I (and you) wanted the whole string, not just the first argument passed to 'hola'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2005 09:51 AM
тАО12-29-2005 09:51 AM
Re: Using a file with messages and using in the message with commands in a function ...
do i have next? :
function hola
{
eval echo $@1
or
eval echo $@#1
}
thanks my friend !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2005 10:00 AM
тАО12-29-2005 10:00 AM
Re: Using a file with messages and using in the message with commands in a function ...
The Forum mangles spaces in posts. I added a comment after the statement. Your script should look like this:
#!/usr/bin/sh
one=`cat messages.txt | grep 001 | cut -d"#" -f2`
valor=300
function hola
{
eval echo $@
}
hola $one
exit 0
The variable is $@ which is the whole set of arguments passed, not $1 which is only the first argument. Run the code the way I posted it and then run it again having changed $@ to $1 to see the difference.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2005 10:11 AM
тАО12-29-2005 10:11 AM
Re: Using a file with messages and using in the message with commands in a function ...
i'm going to explain you exactly how script looks like:
File named messages:
001#`date=+'%Y%m%d'`=DEPURACION:=$vv=bytes=from=$hora=inicial=to=$hora=final
002#`date=+'%Y%m%d'`=$vv=bytes=deleted=from=$horainicial=to=$horafinal
003#`date=+'%Y%m%d'`=There=are=not=core=files=to=be=deleted
004#`date=+'%Y%m%d'`=PROBLEMS=TO=DELETE=FILES=$v=bytes=con=$r2
005#"CORE=FILES"
Function:
function notifica
{
one=`echo $1 | sed 's/=/ /g'`
two=`echo $2 | sed 's/=/ /g'`
three=`echo $3 | sed 's/=/ /g'`
echo "$one" >> ${log_monitoring} #Sending message to log
echo "$two" | mailx -s "$three" 123456789@patito.com #Sending message to cellular
#echo "$three" > /dev/console #Sending message to server console
}
If i see $log_monitoring has:
..........
..........
`date +'%Y%m%d'` DEPURACION: $vv bytes from $hora inicial to $hora final
`date +'%Y%m%d'` DEPURACION: $vv bytes from $hora inicial to $hora final
`date +'%Y%m%d'` DEPURACION: $vv bytes from $hora inicial to $hora final
`date +'%Y%m%d'` DEPURACION: $vv bytes from $hora inicial to $hora final
What do i must do for format date appears correctly and not the command `date +'%Y%m%d'` ?
Thanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2005 11:47 AM
тАО12-29-2005 11:47 AM
Re: Using a file with messages and using in the message with commands in a function ...
As I noted, you need to do something like this:
function notifica
{
one=`echo $@ | sed 's/one/ONE/g'`
eval echo ${one} >> ${log_monitoring}
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2005 04:55 AM
тАО12-30-2005 04:55 AM
Re: Using a file with messages and using in the message with commands in a function ...
thanks for your answer !!!
look at this function, now is:
Function:
function notifica
{
one=`echo $1 | sed 's/=/ /g'`
two=`echo $2 | sed 's/=/ /g'`
three=`echo $3 | sed 's/=/ /g'`
eval echo $one >> ${log_monitoring} #Sending message to log
eval echo $two | mailx -s "$three" 123456789@patito.com #Sending message to cellular
eval echo $three > /dev/console #Sending message to server console
}
You have already taught how execute a string !!
really thank you very much !!!
Manuales.
God Bless you !!
<><
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2005 04:58 AM
тАО12-30-2005 04:58 AM