You are not logged in.
I did this script to backup the folder structure of some paths in my external hdd. The file is backup.sh and I put it in ~/.config/backup.sh
DATETIME=$(date +"[%d-%b-%Y][%H.%M.%S]")
OUTPUT="/media/pino/externalHD/backup"
mkdir -p "$OUTPUT/$DATETIME"
linuxdir2html "/media/pino/externalHD/files" > "$OUTPUT/$DATETIME/FolderStrucuture.html"so when I run ./media/pino/.config/backup.sh, the html files are correctly generated and backupped
Then I created this crontab:
crontab -e0 10 * * * /home/pino/.config/backup.shI wait 10 a.m. and the folder (mkdir -p "$OUTPUT/$DATETIME") is created (so the script is run) but after 5-10min the html file is not generated.
If I try to edit again crontab, nano editor is opened but an error in terminal show up before nano is opened (error below). If I add a new crontab line (ignoring the error), it is not saved, any edit I try to do in crontab doesn't go. It seems like crontab got broken after the backup.sh command). This is the error that shows up a moment before opening nano:
crontab -ecrontab: no changes made to crontabWhy it works if I run it manually but using crontab not?
I use crontab for other tasks so it works, the service is working correctly.
Last edited by pepper (2021-12-23 19:51:44)
Offline
crontab -l
stat /var/spool/cron/pino
cat /var/spool/cron/pino
ls /tmp/cron*
echo $EDITOR
type nano
EDITOR=/usr/bin/nano crontab -eEdit: also backup.sh doesn't have a shebang - is it at least executable?
stat /home/pino/.config/backup.sh(Also I don't have to guess your username ;-)
Last edited by seth (2021-12-23 10:11:48)
Offline
You need to add to .zshrc or .bashrc
export VISUAL="nano"Last edited by robson75 (2021-12-23 11:51:49)
Arch Linux Xfce - 64Bit Linux User #621110
Offline
crontab -l (mini_backups.sh is another script, it continue working even when backup.sh doesn't work)
0 * * * * /home/pino/.config/mini_backups.sh
0 10 * * * /home/pino/.config/backup.shstat /var/spool/cron/pino
File: /var/spool/cron/pino
Dim.: 106 Blocchi: 8 Blocco di IO: 4096 file regolare
Device: 254,1 Inode: 10747955 Links: 1
Accesso: (0600/-rw-------) Uid: ( 1000/ pino) Gid: ( 1000/ pino)
Accesso : 2021-12-23 09:56:01.707422800 +0100
Modifica : 2021-12-23 09:55:49.877422902 +0100
Cambio : 2021-12-23 09:55:49.877422902 +0100
Creazione: 2021-12-23 09:55:49.877422902 +0100File: /var/spool/cron/pino
0 * * * * /home/pino/.config/mini_backups.sh
0 10 * * * /home/pino/.config/backup.shls /tmp/cron*
zsh: no matches found: /tmp/cron*echo $EDITOR (yes, I use mousepad now, but the problem is the same even if I open it with nano)
mousepadtype nano
nano is /usr/bin/nanotype mousepad
mousepad is /usr/bin/mousepadEdit: also backup.sh doesn't have a shebang - is it at least executable?
Yes it has execution permissions (sudo chmod +x backup.sh) and it has also #!/bin/bash at the beginning
Offline
"crontab: no changes made to crontab" suggests that the crontab tempfile is edited and closed w/o changes but I can't see anything in your setup that would promote that - is there a stale crontab process around?
About the main problem: is the script still running?
ps aux | grep -E '(crontab|backup|linuxdir)'Try
time linuxdir2html "/media/pino/externalHD/files" > "$OUTPUT/$DATETIME/FolderStrucuture.html" 2>&1And one more thing:
The file is backup.sh and I put it in ~/.config/backup.sh
…
so when I run ./media/pino/.config/backup.sh
Those are not the same files.
Offline
I made a mistake in copying "./media/pino/.config/backup.sh", the right path is ~/.config/backup.sh.
Anyway I know why crontab returns error before opening mousepad. It's because there was another mousepad opened, so if I have 1 instance of mousepad opened and I run crontab -e, it returns "crontab: no changes made to crontab" even before opening the second instance of mousepad itself.
Now there is only one problem, when I run manually the script, it performs all backup correctly, but when a cronjob executes it, it can only create the folder with date-time (mkdir -p "$OUTPUT/$DATETIME") and no file is generated. Maybe because the cronjob doesn't have the write permissions in /media/pino/ path (where the external hard drive is mounted) ?
time ./backup.sh15:30:55 Root index directory: [/media/pino/externalHD/files]
15:33:30 Wrote output to: /media/pino/externalHD/backup/[23-dic-2021][15.30.55]/FolderStrucuture.html
./backup.sh 20,45s user 16,89s system 23% cpu 2:40,12 totalOffline
The idea was to time the linuxdir2html call inside the script and log that into the FolderStrucuture.html to see whether it's run at all and writes there (as time will create some output)
Offline
$ time linuxdir2html "/media/pino/externalHD/files" > "/media/pino/externalHD/backup/FolderStrucuture.html" 2>&1it creates a file in /media/pino/externalHD/backup/FolderStrucuture.html with inside:
usage: linuxdir2html [-h] [--child CHILD] [--startswith STARTSWITH] [--hidden]
[--links] [-v] [--version]
pathToIndex outputfile
linuxdir2html: error: the following arguments are required: outputfileOffline
Well, looks like a syntax error…
linuxdir2html "/media/pino/externalHD/files" "$OUTPUT/$DATETIME/FolderStrucuture.html"Offline
$ time linuxdir2html "/media/pino/externalHD/files" "/media/pino/externalHD/backup/FolderStrucuture.html" 2>&118:06:58 Root index directory: [/media/pino/externalHD/files]
18:07:05 Wrote output to: /media/pino/externalHD/backup/FolderStrucuture.html
linuxdir2html "/media/pino/externalHD/files" 2>&1 4,69s user 1,95s system 99% cpu 6,666 totalIt generates a FolderStructure.html with no folder structure inside (but linuxdir2html correctly created a html files with header, icons etc..).
Last edited by pepper (2021-12-23 17:14:42)
Offline
No, literally use
linuxdir2html "/media/pino/externalHD/files" "$OUTPUT/$DATETIME/FolderStrucuture.html"in your script. No time, no redirection, no nothing.
Offline
mm ok, but this string
linuxdir2html "/media/pino/externalHD/files" "$OUTPUT/$DATETIME/FolderStrucuture.html"it is already (exactly) what there is inside the script (previously I added the redirection because I read it in your comment in order to perform the the test)
Last edited by pepper (2021-12-23 17:33:48)
Offline
Not according to your OP - you had no parameter for the outpu, but redirected it (the ">" between the path and the html output file) which according to the error you got,is malformed.
Offline
Problem solved. The problem was that binaries installed using pip (python packages) are not in the default linux bin folder. I need to put the full path of linuxdir2html that is in /home/pino/.local/bin/
Thanks for your time and patience.
Offline