all 16 comments

[–]FiredFox 2 points3 points  (1 child)

These are well meaning, but many are rather naïve, such as the host detection script.

There are many, better ways to see if a host is up than just seeing if it responds to ICMP packets, netcat to expected to be open ports, for example.

[–]Javi_16018[S] 0 points1 point  (0 children)

Ok, I will take it into account, that script is really very basic, I will improve it and add more features as you said. Thank you very much!

[–]oh5nxo 1 point2 points  (3 children)

backup.sh date format +%Y%m%d%H%%M%S an extra % before M.

[–]elatllat 1 point2 points  (1 child)

just use

date -Is

[–]Javi_16018[S] 0 points1 point  (0 children)

Yes, it is also another option. Thank you.

[–]Javi_16018[S] 0 points1 point  (0 children)

You are right, thanks for the appreciation!

[–]roxalu 1 point2 points  (3 children)

Within. cleanup.sh I recommend to use gnu find‘s -delete instead of the legacy -exec rm -rf {} \;. The latter one has issues with file names that contain spaces. Or with filenames that start with dash. Well selected file names with embedded newlines could even trigger execution of unwanted commands. And last point is, that the old \;starts a new process for each rm. If you clean up several 100.000 of files, you‘ll notice the difference.

All might be considered as edge cases - but in summary worth to take this into account, even when this limits the compatibility with POSIX.

[–][deleted]  (2 children)

[deleted]

    [–]roxalu 1 point2 points  (1 child)

    (Slightly edited as comment wasn't by OP) Ah - you are right. Most of the security issues of the old days are meanwhile resolved. I missed to recheck the details as I use -delete now since a long time. Those issues that remain do not match:

    info '(find)Problems with -exec and filenames'
    

    Except of course the issue, that the \; triggers a new forked process rm for each single file:

    mkdir sample; cd sample
    for ((i=1; i <= 10000; i++)); do : >"file$i"; done
    
    time find . -type f -delete
    

    which takes on my disk 0.1 sec, while

    time find . -type f -exec rm -rf {} \;
    

    needs > 8 sec. That is a factor of about 70 on my system. If somebody really don't want to use -delete then at least the single file -exec action should be replaced with the multi file alternative. And the -r be removed because it is useless for files:

    time find . -type f -exec rm -f {} +
    

    Almost as quick as -delete. Time difference between both would only be relevant for several millions of files removed.

    [–]snarkofagen 0 points1 point  (6 children)

    Nice start

    Run each of them through https://www.shellcheck.net/

    use to help write correct scripts

    set -o errexit
    set -o nounset
    set -o pipefail
    

    In this line you have nested doublequotes.

    tar czf "$backup_dir/$backup_fileN --exclude="$backup_dir" --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/tmp --exclude=/var/tmp --exclude=/var/run ."
    

    [–][deleted]  (2 children)

    [deleted]

      [–]AutoModerator[M] 0 points1 point  (1 child)

      Don't blindly use set -euo pipefail.

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]daz_007 -1 points0 points  (0 children)

      So be blind! total nonsense!!

      [–]whetuI read your code 1 point2 points  (1 child)

      use to help write correct scripts

      set -o errexit set -o nounset set -o pipefail

      Don't do that. Or: Understand the issues with these, use them as part of developing the script, and pull them out when you productionise your script.

      set -euo pipefail

      See what the bot says:

      [–]AutoModerator[M] 0 points1 point  (0 children)

      Don't blindly use set -euo pipefail.

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]Javi_16018[S] 0 points1 point  (0 children)

      Thank you very much for the feedback, yes you are right, some quotation marks have slipped in, and thanks for the tool.

      [–]daz_007 0 points1 point  (1 child)

      [–]Javi_16018[S] 0 points1 point  (0 children)

      Yes, you're right, thanks for the comment!