diff --git a/lib/rdk/Start_MaintenanceTasks.sh b/lib/rdk/Start_MaintenanceTasks.sh index 88490b42..2ba2a1e9 100644 --- a/lib/rdk/Start_MaintenanceTasks.sh +++ b/lib/rdk/Start_MaintenanceTasks.sh @@ -143,15 +143,24 @@ runMaintenanceLogUploadTask() if [ -f "$LOG_UPLOAD_BIN_PATH" ]; then logUploadLog "Starting log upload" - upload_protocol=$(grep 'LogUploadSettings:UploadRepository:uploadProtocol' /tmp/DCMSettings.conf | cut -d '=' -f2 | sed 's/^"//; s/"$//') - [ -z "$upload_protocol" ] && upload_protocol='HTTP' - logUploadLog "upload_protocol: $upload_protocol" - - httplink=$(grep 'LogUploadSettings:UploadRepository:URL' /tmp/DCMSettings.conf | cut -d '=' -f2 | sed 's/^"//; s/"$//') - if [ -n "$httplink" ]; then - upload_httplink="$httplink" + + if [ -L "/tmp/DCMSettings.conf" ]; then + logUploadLog "ERROR: DCMSettings.conf is a symlink" else - logUploadLog "'LogUploadSettings:UploadRepository:URL' is not found in DCMSettings.conf" + upload_protocol=$(grep 'LogUploadSettings:UploadRepository:uploadProtocol' /tmp/DCMSettings.conf | cut -d '=' -f2 | sed 's/^"//; s/"$//') + [ -z "$upload_protocol" ] && upload_protocol='HTTPS' + logUploadLog "upload_protocol: $upload_protocol" + + httplink=$(grep 'LogUploadSettings:UploadRepository:URL' /tmp/DCMSettings.conf | cut -d '=' -f2 | sed 's/^"//; s/"$//') + if [ -n "$httplink" ]; then + if echo "$httplink" | grep -qE '^https?://'; then + upload_httplink="$httplink" + else + logUploadLog "ERROR: Invalid URL format in DCMSettings.conf" + fi + else + logUploadLog "'LogUploadSettings:UploadRepository:URL' is not found in DCMSettings.conf" + fi fi if [ "$BUILD_TYPE" != "prod" ] && [ -f /opt/dcm.properties ]; then diff --git a/lib/rdk/core_shell.sh b/lib/rdk/core_shell.sh index 73382e98..0a2563d2 100755 --- a/lib/rdk/core_shell.sh +++ b/lib/rdk/core_shell.sh @@ -65,12 +65,12 @@ upload() { fi fi # Checking whether cores are leading to /opt size exceeding. - count=`ls $CORE_PATH | grep $process | wc -l` + count=`ls $CORE_PATH | grep "$process" | wc -l` while [ $count -gt 5 ]; do - oldcore=`ls -t $CORE_PATH | grep $process | tail -1` + oldcore=`ls -t $CORE_PATH | grep "$process" | tail -1` echo $(/bin/timestamp) "Deleting $oldcore as the same process has more than 5 cores in $CORE_PATH" >> $LOG_PATH/core_log.txt - rm -rf $CORE_PATH/$oldcore - count=`ls $CORE_PATH | grep $process | wc -l` + rm -rf "$CORE_PATH/$oldcore" + count=`ls $CORE_PATH | grep "$process" | wc -l` done sh /lib/rdk/diskCleanup.sh diff --git a/lib/rdk/cronjobs_update.sh b/lib/rdk/cronjobs_update.sh index fd264c21..027a906c 100644 --- a/lib/rdk/cronjobs_update.sh +++ b/lib/rdk/cronjobs_update.sh @@ -50,24 +50,31 @@ if [ $# -ne 3 ] && [ "$1" = "add" -o "$1" = "update" ]; then fi LOCK="/tmp/.cronjob.LCK" +if [ -L "$LOCK" ]; then + rm -f "$LOCK" +fi exec 8>$LOCK -flock -x 8 +flock -x -w 30 8 || exit 1 remove() { - sed -i "/[A-Za-z0-9]*$1[A-Za-z0-9]*/d" $current_cron_file + escaped=$(printf '%s\n' "$1" | sed 's/[][\\.^$*\/]/\\&/g') + sed -i "/[A-Za-z0-9]*${escaped}[A-Za-z0-9]*/d" "$current_cron_file" } add() { - echo "$1" >> $current_cron_file + if echo "$1" | grep -q '[;&]'; then + exit 1 + fi + echo "$1" >> "$current_cron_file" } check_entry() { - output=`grep -c "$1" $current_cron_file` + output=`grep -cF "$1" "$current_cron_file"` echo "`/bin/timestamp` output=$output" >> $log_file - echo $output + echo "$output" } @@ -77,14 +84,14 @@ if [ -f /etc/os-release ]; then touch /var/spool/cron/root pid=`pidof crond` echo "`/bin/timestamp` crond pid: $pid" >> $log_file - if [ -z $pid ]; then + if [ -z "$pid" ]; then crond -b -L /dev/null -c /var/spool/cron/ fi fi current_cron_file="/tmp/cron_list" -crontab -l -c /var/spool/cron/ > $current_cron_file +crontab -l -c /var/spool/cron/ > "$current_cron_file" echo "`/bin/timestamp` :Arguments - 1st:$1, 2nd:$2, 3rd:$3" >> $log_file if [ "$1" = "remove" ]; then @@ -110,7 +117,7 @@ fi # update the new cron entries to root cron -crontab $current_cron_file -c /var/spool/cron/ +crontab "$current_cron_file" -c /var/spool/cron/ # add flock -u to unlock the file descriptor before removing the file flock -u 8 diff --git a/lib/rdk/warehouse-reset.sh b/lib/rdk/warehouse-reset.sh index 919da39a..8d26e921 100644 --- a/lib/rdk/warehouse-reset.sh +++ b/lib/rdk/warehouse-reset.sh @@ -80,7 +80,7 @@ fi echo "Warehouse Reset:Starting file cleanUp" # /opt override cleanup -ls /opt/*.conf | grep -v receiver.conf | xargs rm +find /opt -maxdepth 1 -name "*.conf" ! -name "receiver.conf" -exec rm {} \; rm -rf /opt/*.ini if [ -f /opt/hosts ]; then rm -rf /opt/hosts; fi if [ -f /opt/dcm.properties ];then rm -rf /opt/dcm.properties ; fi