A
A
Anatoly2018-06-02 13:13:59
linux
Anatoly, 2018-06-02 13:13:59

How to mount disk via cron?

There is a file /usr/bin/test.sh with launch rights, the text is something like this:

#!/bin/bash

WIN_MOUNT=/mnt/backup
WIN_SHARE=//192.168.5.15/backup
WIN_USER=WinUser
WIN_PASS=MyPassword
BACKUP_DIR=$WIN_MOUNT/backup-sites

mkdir -p $WIN_MOUNT
mount.cifs $WIN_SHARE $WIN_MOUNT -o user=$WIN_USER,password=$WIN_PASS

копирую файлы

umount $WIN_MOUNT

And when you run test.sh, it mounts and copies, and then unmounts the disk.
After I registered this case in cron, I do not mount.
crontab -e
* * * * * test.sh
systemctl restart cron
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2018-06-02
@Tolly

I registered the line in crontab:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin it
worked
although I copied it from the console:
echo $PATH

P
pfg21, 2018-06-02
@pfg21

write the mount to the systemd unit if you have it in the system.
or better yet, read systemd.mount

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question