Automatic Alert
I am new to Linux, I am learning shell scripts.
I wrote a script which will alert/ give message from Monday to Friday(5 weekdays) at 8:15 that "Welcome to Work Place" #!bin/bash HOUR='date | grep {'echo $4'}' MINUTE='date |grep {'grep $5'}' DAY='date | grep ('cal[Mon - Fri]')' while true; do if [$HOUR -eq 8] -a [$MINUTE -eq 15]; then echo $DAY "Welcome to work place" else sleep 13500s fi done I got the error message that /date command not found on line 2, 3 and line 4. I need your assistance and be blessed. |
try the full path "/bin/date"
|
Automatic alert
Quote:
This is the script: #!/bin/bash /bin/date hour='date |grep {'echo $4'}' min='date |grep {'echo $5'}' day='date |grep {'[cal (Mon - Fri)]'} while true; do if [$HOUR -eq 21] = [$MIN -eq 45]; then echo $DAY "Good Morning" else sleep 13500s fi done The error message day: line 3: }: command not found day: line 4: }: command not found day: line 5: syntax error near unexpected token `(' day: line 5: `day='date |grep {'[cal (Mon - Fri)]'}' :newbie: |
Hint:
time='date | awk {'print $4}' Will assign time to the 4th variable and looking at the ouput of the date command would be time. You can use string commands to seperate out hours and minutes. |
Quote:
#!/bin/bash /bin/date hour='date | awk {'print $4'}' min='date | awk {'print $5'}' day='date |awk {'print [cal (Mon - Fri)]'}' while true; do if [$HOUR -eq 8] -a [$MIN -eq 15]; then print -v $DAY "Good Morning" else sleep 13500s fi done Error message: day: line 3: }: command not found day: line 4: }: command not found day: line 5: syntax error near unexpected token `(' day: line 5: `day='date |awk {'print [cal (Mon - Fri)]'}' |
Lets try again
hour=$(date | awk {'print $4'}) |
How about this:
Code:
#!/bin/bash |
Automatic alert
Quote:
awk: {print [cal (Mon - Fri)]} awk: ^ syntax error awk: {print [cal (Mon - Fri)]} awk: ^ syntax error day: line 10: [10:16:27: command not found |
Instead of using "awk" or "grep" to get what you want, it's a lot easier just to use
date's own options for date formatting. ie: Code:
HOUR=`/bin/date +%H` A few other remarks: -I doubt that there is something like a "print" command in Bash. Use "echo" to print messages on a terminal instead. Check out "man bash" for this one. -Your loop isn't ending. You should add an "exit" after echo'ing your "Good morning" message. |
The main problem with your script is that you are using an apostrophe instead of a `.
When you need command substitution, you have to use Code:
`command` E.g. the line Code:
DAY=`date | grep (`cal[Mon - Fri]`)` Code:
DAY=$(date | grep ( $(cal[Mon - Fri]) ) ) Lotharster |
All times are GMT -5. The time now is 11:05 AM. |