I'm migrating some software from Unix to Linux.
I have the following script; it is a trigger of a file transfer.
What do the exec
commands do?
Will they work also on Linux?
#!/bin/bash
flog=/mypath/log/mylog_$8.log
pid=$$
flog_otherlog=/mypath/log/started_script_${8}_${pid}.log
exec 6>&1
exec 7>&2
exec >> $flog
exec 2>&1
exec 1>&6
exec 2>&7
/usr/local/bin/sudo su - auser -c "/mypath/bin/started_script.sh $1 $pid $flog_otherlog $8"
The started script is the following:
#!/bin/bash
flusso=$1
pidpadre=$2
flogcurr=$3
corrid=$4
pid=$$
exec >> $flogcurr
exec 2>&1
if [ $1 = pippo ] || [ $1 = pluto ] || [ $1 = paperino ]
then
fullfile=${myetlittin}/$flusso
filename="${flusso%.*}"
datafile=$(ls -le $fullfile | awk '{print $6, " ", $7, " ", $9, " ", $8 }')
dimfile=$(ls -le $fullfile | awk '{print $5 " " }')
aaaammgg=$(ls -E $fullfile | awk '{print $6}'| sed 's#-##g')
aaaamm=$(echo $aaaammgg | cut -c1-6)
dest_dir=${myetlwarehouse}/mypath/${aaaamm}
dest_name=${dest_dir}/${filename}_${aaaammgg}.CSV
mkdir -p $dest_dir
cp $fullfile $dest_name
rc_copia=$?
fi
I will change ls -le
into ls -l --time-style="+%b %d %T %Y"
and ls -E
into ls -l --time-style=full-isoand
in Linux.
ls
./usr/local/bin/sudo su - auser -c "/mypath/bin/started_script.sh $1 $pid $flog_otherlog $8"
has some serious security problems. I would write this as two commands, one that generates a safely-escaped command to run and a second one that runs it:printf -v args '%q ' "$1" "$pid" "$flag_otherlog" "$8"
and thensudo su - auser -c "/mypath/bin/started_script $args"
$'$(rm -rf ~)\'$(rm -rf ~)\''
(or code that downloads and runs a rootkit, or so forth) in a place where it got substituted into$1
or$8
or so forth, you would have a very bad day. (I don't know the context of this script, but if it handles uncontrolled content like uploaded files, that's extra dangerous).