scipt help elif
hi can someone please tell me how to intgegrate
current_date=`date +%s` for i in $( ls ); do tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","` check for any current recording if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -lt $((current_date)) ]; then recording=1 fi done as an additional parameter to no suspend in to: #!/bin/bash sleep 30 if [ `netstat -t | grep -c ":9982"` -ge 3 ] then exit 1 elif [ `netstat -t | grep -c "192.168.0.:microsoft-ds ESTABLISHED"` -ne 0 ] then exit 1 else echo pm-suspend fi Thank you |
I tried
Code:
#!/bin/bash Code:
/home/billy/bin/grep.sh: line 12: $i: syntax error: operand expected (error toke n is "$i") |
Do you want to combine both parts of the sript? Please mention what is your ultimate goal for which you're writing this script? I don't understand the use of definning `date +%s` as curent_date, and is it correct... current_date equal to date +%s ?
|
It is a suspend script which checks for connections on port 9982 and connections to my windows share before disconnecting.
I am trying to add in a test which checks for an active recording by inserting the relevant section of the other script which does work. I just not sure of the if logic. |
Just check this:
Quote:
-- ADDTION --- Just below the #!/bin/bash line, add a line, set -xv for debugging. It will give you clear idea by showing line by line output of the script. Later you can remove or # this line. Quote:
|
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
1) Clean, consistent formatting makes code readable and more easily debuggable. Be liberal with whitespace; indent all your sub-commands evenly and separate logical sections with empty lines. Never just line everything up on the left edge. Add comments anywhere the code isn't completely obvious (and remember, what seems obvious to you now will not be so a year or so down the line). 2) $(..) is highly recommended over `..` 3) Code:
for i in $( ls ); do Just use a simple globbing pattern here: Code:
for i in * ; do Code:
tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` Since the file contents are unknown to me, I can't be sure of the exact solution, but it would probably look something like this: Code:
tmp_start=$( awk -F '[ ,]' '/"start"/ { print $3 }' "$i" ) http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes 5) Code:
if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -lt $((current_date)) ]; then http://wiki.bash-hackers.org/commands/classictest http://wiki.bash-hackers.org/syntax/...nal_expression http://wiki.bash-hackers.org/syntax/arith_expr And you don't need $((..)) unless you're actually evaluating an expression, BTW. Code:
if (( tmp_stop > -gt current_date && tmp_start < current_date ]; then |
Thanks for the tips!
I have it working , I had missed out part of the script, here is the working script: Code:
#!/bin/bash Code:
{ |
All times are GMT -5. The time now is 03:16 AM. |