You are not logged in.

#1 2021-12-23 09:25:21

pepper
Member
Registered: 2017-12-09
Posts: 135

[SOLVED] crontab problem

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 -e
0 10 * * * /home/pino/.config/backup.sh

I 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 -e
crontab: no changes made to crontab

Why 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

#2 2021-12-23 10:10:13

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

crontab -l
stat /var/spool/cron/pino
cat /var/spool/cron/pino
ls /tmp/cron*
echo $EDITOR
type nano
EDITOR=/usr/bin/nano crontab -e

Edit: 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

#3 2021-12-23 11:46:01

robson75
Member
From: Poland
Registered: 2020-06-28
Posts: 144

Re: [SOLVED] crontab problem

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

#4 2021-12-23 12:51:15

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

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.sh

stat /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 +0100

File: /var/spool/cron/pino

0 * * * * /home/pino/.config/mini_backups.sh
0 10 * * * /home/pino/.config/backup.sh

ls /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)

mousepad

type nano

nano is /usr/bin/nano

type mousepad

mousepad is /usr/bin/mousepad

Edit: 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

#5 2021-12-23 13:41:25

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

"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>&1

And 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

#6 2021-12-23 14:36:20

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

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.sh
15: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 total

Offline

#7 2021-12-23 14:44:50

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

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

#8 2021-12-23 16:40:14

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

$ time linuxdir2html "/media/pino/externalHD/files" > "/media/pino/externalHD/backup/FolderStrucuture.html" 2>&1

it 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: outputfile

Offline

#9 2021-12-23 16:45:48

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

Well, looks like a syntax error…

linuxdir2html "/media/pino/externalHD/files" "$OUTPUT/$DATETIME/FolderStrucuture.html"

Offline

#10 2021-12-23 17:11:34

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

$ time linuxdir2html "/media/pino/externalHD/files" "/media/pino/externalHD/backup/FolderStrucuture.html" 2>&1
18: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 total

It 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

#11 2021-12-23 17:19:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

No, literally use

linuxdir2html "/media/pino/externalHD/files" "$OUTPUT/$DATETIME/FolderStrucuture.html"

in your script. No time, no redirection, no nothing.

Offline

#12 2021-12-23 17:33:06

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

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

#13 2021-12-23 17:54:39

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,366

Re: [SOLVED] crontab problem

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

#14 2021-12-23 19:51:28

pepper
Member
Registered: 2017-12-09
Posts: 135

Re: [SOLVED] crontab problem

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

Board footer

Powered by FluxBB