In a batch file I have
findstr SWITCHIDENTITY rf_monitor.out >nul 2>&1 && set IDENTITY_FOUND=true
findstr SWITCHUTILITY rf_monitor.out >nul 2>&1 && set UTILITY_FOUND=true
findstr "GP Manager connection successful" rf_monitor.out >nul 2>&1 && set GPMANAGER_FOUND=true
with echo on, below is what I see
D:\cvstags\trunk\regfortcms\install\win\scripts>findstr SWITCHIDENTITY rf_monito
r.out 1>nul 2>&1 && set IDENTITY_FOUND=true
D:\cvstags\trunk\regfortcms\install\win\scripts>findstr SWITCHUTILITY rf_monitor
.out 1>nul 2>&1 && set UTILITY_FOUND=true
D:\cvstags\trunk\regfortcms\install\win\scripts>findstr "GP Manager connection s
uccessful" rf_monitor.out 1>nul 2>&1 && set GPMANAGER_FOUND=true
**&& was unexpected at this time.**
Why do I get that && was unexpected at this time? If I type the three commands myself on the DOS prompt I don't get any such message. Please advice.
Goddammit, the error message had been not about the lines I posted but about my usage of && in an IF condition. It seems that I have to use like IF condition1 IF condition2 .
Related
How to check response coming from a command while using SSHOperator?
t1 = SSHOperator(ssh_conn_id='conn_box2',
task_id='t1',
command='Rscript /code/demo.R',
do_xcom_push=True,
response_check=lambda response: True if "status:200" in response.text else False,
dag=dag
)
My R scripts returns status:200 if the execution goes well. And I want to track it. My task t1 should only complete if status is 200.
If R script returns status:300 its a failed one. But since the execution is completed without any error in UI task turns into green(which i don't want)
I code above is able to capture the response in xcom, but how do i validate it?
Try the following code:
bash_command = """
set -e;
Rscript /code/demo.R | grep 'status:200' &> /dev/null
if [ $? == 0 ]; then
echo "Task Successful"
else
echo "Task Failed"
exit 1
fi
"""
t1 = SSHOperator(ssh_conn_id='conn_box2',
task_id='t1',
command=bash_command,
dag=dag)
Alternatively, you can also use the following bash_command:
if Rscript /code/demo.R | grep -q 'status:200'; then
echo "Task Successful"
else
echo "Task Failed"
exit 1
fi
The SSHOperator does not have response_check parameter.
Airflow is unable to interpret exit command
[2021-09-07 06:36:58,164] {ssh.py:142} INFO - ps_count is 23, There might be some processes are running
[2021-09-07 06:36:58,169] {taskinstance.py:1455} ERROR - SSH operator error: error running cmd:
code:
set -e;
ps_count=jpsexec | grep -v execute | wc -l
if [ $ps_count -ne 0 ]
then
echo "ps_count is $ps_count, There might be some processes are running"
exit 1
else
echo "All processed were stopped..!"
fi
I have gammu-smsd up and running on a raspberry-pi with jessie. I am using runonreceive to process incoming texts. I have the following script working using runonreceive. In the script I am calling gammu sendsms instead of gammu-smsd-inject as the documentation states. All other references state gammu will not work while gammu-smsd daemon is running. The only reason I got this to work is after pulling my hair out trying to get gammu-smsd-inject to work. Can anyone explain what is going on?
RunOnReceive = /home/jaalfs/bin/sms_back.sh
sms_back.sh
#!/bin/bash
from=$SMS_1_NUMBER
echo "sms_back" >> /home/jaalfs/bin/sms_back.log
echo "Test from: $from" >> /home/jaalfs/bin/sms_back.log
echo -e "\n"
if [ "$from" != "+1310xxxxxxx" ]; then
echo -e "not accepted number \n" >> /home/jaalfs/bin/sms_back.log
exit 0
else
echo "accepted number" >> /home/jaalfs/bin/sms_back.log
echo "hello world!!!!!!" | sudo gammu sendsms TEXT "$from"
echo -e " text sent back \n" >> /home/jaalfs/bin/sms_back.log
exit 0
fi
exit 1
I am using sqlplus in a shell script and I am using WHENEVER SQLERROR EXIT 8 and WHENEVER OSERROR EXIT 9 so that I can catch errors using $?.
I will be putting this code on a server that I know gets the password expiry warning/error 'ORA-28011'.
My question is, will my script catch on 'ORA-28011' even though it isn't really an error? If so, how would I go about ignoring it?
My (simplified) code, if it helps:
[...]
CONNECTION_STRING=$USER/$PASS#$TNS
RESULT=$(sqlplus -s /nolog <<-EOF
WHENEVER OSERROR EXIT 9;
WHENEVER SQLERROR EXIT 8;
$OPTIONS
CONNECT $CONNECTION_STRING
$DB_SQL
COMMIT;
EOF)
RETURN_CODE=$?
echo "db_exec: Result -> $RETURN_CODE\n$RESULT"
if [ $RETURN_CODE -eq 0 ]
then
echo "$RESULT"
return 0
else
echo "db_exec: Failed"
return 1
fi
In case anyone is interested, I solved this problem.
ORA-28011 and ORA-28002 do not cause SQL*Plus to exit when using WHENEVER SQLERROR EXIT # or WHENEVER OSERROR EXIT # but will appear in the result. Therefore the code in my question will work, but I need to remove these errors. My updated code is below:
# Run the SQL with the options specified
RESULT=$(sqlplus -s /nolog <<-EOF
WHENEVER SQLERROR EXIT 4;
WHENEVER OSERROR EXIT 5;
SPOOL $TEMP_FILE;
$DB_OPTIONS
$DB_CONNECT
$DB_SQL
COMMIT;
EOF)
# Save the return code
RETURN_CODE=$?
# Log the result
echo "Result -> Code: $RETURN_CODE\n$RESULT" 1>&2
if [ $( grep -cE '^ORA-28002:|^ORA-28011:' $TEMP_FILE) -ge 1 ]
then
echo "Warning -> Password Expiry \n$(grep '^ORA-' $TEMP_FILE)" 1>&2
fi
# Check the return code and catch any SQL*Plus (SP2-) errors that might not have presented an error code
if [ $RETURN_CODE -eq 0 ] && [ $(grep -c '^SP2-[0-9][0-9][0-9][0-9]' $TEMP_FILE) -eq 0 ]
then
# Echo the result, but remove any lines regarding password expiry
echo "$RESULT" | grep -v "^ERROR:" | grep -v "^ORA-[0-9][0-9][0-9][0-9][0-9]"
rm $TEMP_FILE
echo "Success" 1>&2
return 0
elif [ $RETURN_CODE -eq 4 ]
then
echo "Failed -> SQL Error \n$(grep '^ORA-' $TEMP_FILE) $(grep '^SP2-' $TEMP_FILE)" 1>&2
return 4
elif [ $RETURN_CODE -eq 5 ]
then
echo "Failed -> OS Error \n$(grep '^ORA-' $TEMP_FILE) $(grep '^SP2-' $TEMP_FILE)" 1>&2
return 5
elif [ $(grep -c "^SP2-[0-9][0-9][0-9][0-9]" $TEMP_FILE) -ne 0 ]
then
echo "Failed -> SQL*Plus Error \n$(grep '^SP2-' $TEMP_FILE)" 1>&2
return 6
else
echo "Unknown error -> $RETURN_CODE\n$RESULT" 1>&2
return 3
fi
I have this piece of code:
echo %ip_address%>%logfile%
echo %hostname%>>%logfile%
echo %duration%>>%logfile%
However, I would like to know if it possible to echo each variable on a separate line.
I have tried the following:
echo %ip_address% && %hostname% && %duration%>c:\text.txt
echo %ip_address% & echo.%hostname% & echo.%duration%>c:\text.txt
None of these work.
Is it possible to time out a user input for the c shell? My code so far is :
#!/bin/csh -f
set COUNT = 5
printf "INFO: Start ok (0/1)? "
set INPUT = 0
while ($COUNT > 0 && $INPUT == 0)
printf "\b%d" "$COUNT"
set INPUT = <$
sleep 1
# COUNT --
end
if ($INPUT == 1) then
./execute.sh
end
If no input is given, I want to execute a shell script; if not i want to skip this part.
Unfortunately, the skript does not skip the input part but waits for the input. Any solutions for this problem?
Thanks a lot guys!!!
try this for non-blocking user input in tcsh shell:
set TMPFILE = `mktemp`
set COUNT = 5
printf "INFO: Start ok (0/1)? "
stty -F /dev/tty -icanon
while ($COUNT > 0 && -z $TMPFILE)
printf "\b%d" "$COUNT"
sleep 1
(dd bs=1 count=1 iflag=nonblock > $TMPFILE) >& /dev/null
set INPUT = `cat $TMPFILE`
# COUNT--
end
stty -F /dev/tty icanon
echo ""
if ("$INPUT" == "1") then
./execute.sh
endif