| | |
problem with variable expansion in shell script
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 12
Reputation:
Solved Threads: 0
Dear all,
I have written a small script which will send me mail on status of server.
I have tested it working fine. I am facing only with message subject
The last part of my script is as below,
cat dailystatus.txt| mail -s "Daily Server Status Report-$yr-$mm-$dd" root@ecms.co.in
The script run perfectly . The variable yr, mm. dd are defined and that is not a problem I have tested it too. But when I receive the mail , I got the subject heading as "Daily Server Status Report-$yr-$mm-$dd" . The variable are not getting replaced by the values,
So I feel that it may not be allowed to put variables with mail command.
Is there is any way so that subject can be read from file. Or any other idea on this.
Thanks
Vinod
I have written a small script which will send me mail on status of server.
I have tested it working fine. I am facing only with message subject
The last part of my script is as below,
cat dailystatus.txt| mail -s "Daily Server Status Report-$yr-$mm-$dd" root@ecms.co.in
The script run perfectly . The variable yr, mm. dd are defined and that is not a problem I have tested it too. But when I receive the mail , I got the subject heading as "Daily Server Status Report-$yr-$mm-$dd" . The variable are not getting replaced by the values,
So I feel that it may not be allowed to put variables with mail command.
Is there is any way so that subject can be read from file. Or any other idea on this.
Thanks
Vinod
Shell Scripting Syntax (Toggle Plain Text)
cat dailystatus.txt| mail -s "Daily Server Status Report-${yr}-${mm}-${dd}" root@ecms.co.in
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Maybe not, but it is still a good practice to get into, especially when using variables mixed in with other characters where the variable does not have whitespace on both sides. But, considering that he is actually getting "-$yr-" (which is the first variable) tells me that the script is not recognizing those "strings" as variables, at all, which the braces can help with.
Edit: If it were that the variables were defined wrong, he would probably wind up with "Report---".
Edit: If it were that the variables were defined wrong, he would probably wind up with "Report---".
Last edited by masijade; Oct 28th, 2007 at 8:38 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Sending email from a shell script (Shell Scripting)
- Using Shell Script how to send mail automatically (Shell Scripting)
- Invoking a shell script (PHP)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP)
- Why my shell script doesn't delete a file ?? (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Compare two dates using Shell Programming
- Next Thread: call the constructor of java class from script
Views: 1943 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






