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
# run piscal
pushd $run_directory >> /dev/null
pushd "$run_directory" >> /dev/null
if [ -z "$test_output_directory" ]; then
eval $piscal_executable
# `piscal_executable` comes from a cfg file and may include args.
eval "$piscal_executable"
else
cp -r "$test_output_directory"/* "$output_directory_base"/
fi
@@ -112,10 +113,10 @@ if [ -z "$suppress_storage_copy" ]; then
if [ ! -f "$mv_script" ]; then
mv_script="/srv/subdir_year.sh"
fi
pushd "$storage_directory"/output >> /dev/null
pushd "$storage_directory/output" >> /dev/null
"$mv_script"
popd >> /dev/null
pushd "$storage_directory"/input >> /dev/null
pushd "$storage_directory/input" >> /dev/null
"$mv_script"
popd >> /dev/null
fi
+18 -11
View File
@@ -118,9 +118,9 @@ fi
## Process task
if [ "$task" = "launch" ]; then
# 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 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
echo still running
exit 1
@@ -143,10 +143,10 @@ if [ "$task" = "launch" ]; then
fi
# 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
echo $! > $pid_path
echo $! > "$pid_path"
echo started
elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then
# 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
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 ps -p $pid > /dev/null; then
if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running
echo running
else
@@ -197,9 +201,9 @@ elif [ "$task" = "cleanup" ]; then
exit 0
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 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
echo still running
exit 1
@@ -214,11 +218,14 @@ elif [ "$task" = "kill" ]; then
exit 0
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 ps -p $pid > /dev/null; then
if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running
kill $pid
kill "$pid"
fi
echo killed
fi