Skip to content

Commit 0723db9

Browse files
committed
fix codacy static code analysis
1 parent 4a1c3ee commit 0723db9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lgsm/modules/command_toggle_cronjobs.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ fn_toggle_cronjob() {
2828

2929
local completejob="${jobschedule} ${lgsmcommand} > ${outputlog} 2> ${errorlog} ${lgsmcomment}"
3030

31-
local currentcrontab=$(crontab -l 2>/dev/null)
31+
local currentcrontab
32+
currentcrontab=$(crontab -l 2>/dev/null)
3233

3334
# If a cronjob for this LinuxGSM command already exists
3435
# ! ($| ) is used to match the end of the line or a space after the command to avoid matching similar commands like ./gameserver update & ./gameserver update-lgsm
3536
if echo "$currentcrontab" | grep -Eq "${lgsmcommand}($| )"; then
3637
# If the existing cronjob was auto-added by LinuxGSM
3738
if echo "$currentcrontab" | grep -E "${lgsmcommand}($| )" | grep -q "${lgsmcomment}"; then
3839
# Remove the existing cronjob
39-
local newcrontab=$(echo "$currentcrontab" | grep -Ev "${lgsmcommand}($| )")
40-
# Update the crontab to keep all cronjobs except the removed one
41-
echo "$newcrontab" | crontab -
40+
local newcrontab
41+
newcrontab=$(echo "$currentcrontab" | grep -Ev "${lgsmcommand}($| )")
4242

43+
# Update the crontab to keep all cronjobs except the removed one
4344
# Check if the crontab was updated successfully
44-
if [ $? -eq 0 ]; then
45+
if echo "$newcrontab" | crontab -; then
4546
fn_print_ok_nl "Removed cronjob for '${lgsmcommand}'"
4647
fn_script_log_pass "Removed the auto-added cronjob for '${lgsmcommand}' from the crontab."
4748
else
@@ -55,10 +56,8 @@ fn_toggle_cronjob() {
5556
fi
5657
else
5758
# Add the job to the crontab while keeping existing cronjobs
58-
printf "%s\n%s\n" "$currentcrontab" "$completejob" | crontab -
59-
6059
# Check if the crontab was updated successfully
61-
if [ $? -eq 0 ]; then
60+
if printf "%s\n%s\n" "$currentcrontab" "$completejob" | crontab -; then
6261
fn_print_ok_nl "Added the cronjob for '${lgsmcommand}'"
6362
fn_script_log_pass "Added the cronjob for '${lgsmcommand}' to the crontab."
6463
else

0 commit comments

Comments
 (0)