Refactor piscal_launcher.sh and piscal_manager.sh for improved quoting and error handling. Ensure proper handling of variables and directory paths to enhance script robustness.

This commit is contained in:
2026-03-18 22:13:50 -04:00
parent 44fd41f0e3
commit 9be068962c
2 changed files with 23 additions and 15 deletions
+5 -4
View File
@@ -92,10 +92,11 @@ if [ ! -d "$run_directory" ]; then
fi fi
# run piscal # run piscal
pushd $run_directory >> /dev/null pushd "$run_directory" >> /dev/null
if [ -z "$test_output_directory" ]; then if [ -z "$test_output_directory" ]; then
eval $piscal_executable # `piscal_executable` comes from a cfg file and may include args.
eval "$piscal_executable"
else else
cp -r "$test_output_directory"/* "$output_directory_base"/ cp -r "$test_output_directory"/* "$output_directory_base"/
fi fi
@@ -112,10 +113,10 @@ if [ -z "$suppress_storage_copy" ]; then
if [ ! -f "$mv_script" ]; then if [ ! -f "$mv_script" ]; then
mv_script="/srv/subdir_year.sh" mv_script="/srv/subdir_year.sh"
fi fi
pushd "$storage_directory"/output >> /dev/null pushd "$storage_directory/output" >> /dev/null
"$mv_script" "$mv_script"
popd >> /dev/null popd >> /dev/null
pushd "$storage_directory"/input >> /dev/null pushd "$storage_directory/input" >> /dev/null
"$mv_script" "$mv_script"
popd >> /dev/null popd >> /dev/null
fi fi
+18 -11
View File
@@ -118,9 +118,9 @@ fi
## Process task ## Process task
if [ "$task" = "launch" ]; then if [ "$task" = "launch" ]; then
# verify process isn't running yet # verify process isn't running yet
pid=$(head -n 1 $pid_path 2>/dev/null) pid="$(head -n 1 "$pid_path" 2>/dev/null)"
# if the pid exists, check the process status using ps # if the pid exists, check the process status using ps
if ps -p $pid &>/dev/null; then if [ -n "$pid" ] && ps -p "$pid" &>/dev/null; then
# if it is in ps, then it's still running # if it is in ps, then it's still running
echo still running echo still running
exit 1 exit 1
@@ -143,10 +143,10 @@ if [ "$task" = "launch" ]; then
fi fi
# launch it, sending error output to file # launch it, sending error output to file
nohup ${command} > $working_directory/$stderr_filename 2>&1 & nohup ${command} > "$working_directory/$stderr_filename" 2>&1 &
# write the PID to a temp file to check for completion later # write the PID to a temp file to check for completion later
echo $! > $pid_path echo $! > "$pid_path"
echo started echo started
elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then
# if the pid doesn't exist, then process hasn't started # if the pid doesn't exist, then process hasn't started
@@ -155,9 +155,13 @@ elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; the
exit exit
fi fi
pid=$(head -n 1 $pid_path 2>/dev/null) pid="$(head -n 1 "$pid_path" 2>/dev/null)"
if [ -z "$pid" ]; then
echo "not started"
exit
fi
# if the pid exists, check the process status using ps # if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running # if it is in ps, then it's still running
echo running echo running
else else
@@ -197,9 +201,9 @@ elif [ "$task" = "cleanup" ]; then
exit 0 exit 0
fi fi
pid=$(head -n 1 $pid_path 2>/dev/null) pid="$(head -n 1 "$pid_path" 2>/dev/null)"
# if the pid exists, check the process status using ps # if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then if [ -n "$pid" ] && ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running # if it is in ps, then it's still running
echo still running echo still running
exit 1 exit 1
@@ -214,11 +218,14 @@ elif [ "$task" = "kill" ]; then
exit 0 exit 0
fi fi
pid=$(head -n 1 $pid_path 2>/dev/null) pid="$(head -n 1 "$pid_path" 2>/dev/null)"
if [ -z "$pid" ]; then
exit 0
fi
# if the pid exists, check the process status using ps # if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running # if it is in ps, then it's still running
kill $pid kill "$pid"
fi fi
echo killed echo killed
fi fi