He comprado un disco duro externo para hacer copias de seguridad programadas de mi macbook pro, presumiblemente bajo cron. Mis comandos rsync funcionan bien cuando los invoco en la línea de comandos bash (interactiva). Pero en cuanto intento hacerlos bajo cron, fallan. De hecho, cron no encuentra archivos en el disco duro externo . El código siguiente lo demuestra.
#!/bin/bash
echo ==========================================
date '+%Y-%m-%d %a %H:%M:%S'
whoami
printenv
find -s /Users/kpr/nDoNotBackup/Dustin /Volumes/oom/tmp -type f -newermt '2021-12-30'
El script se llama zee. Para poner tanto el comando interactivo como el comando cron en shells idénticos, he utilizado env -i /bin/bash -login -c
. Para ello, he seguido https://stackoverflow.com/questions/9671027/sanitize-environment-with-command-or-bash-script .
Primera interactiva:
~/tmplocal/DUMS/zee> env -i /bin/bash -login -c '/Users/kpr/u/kh/bin/zee >> /Users/kpr/tmplocal/DUMS/zee/out.txt 2>&1'
y luego
~> crontab -l
00 16 * * * $HOME/u/kh/bin/jaw20200410cronmakeccalfile.sh
05 22 * * * env -i /bin/bash -login -c '/Users/kpr/u/kh/bin/zee >> /Users/kpr/tmplocal/DUMS/zee/out.txt 2>&1'
~>
En out.txt, las invocaciones se distinguen por sus valores de PWD.
==========================================
2021-12-30 Thu 22:03:43
kpr
PATH=/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin
PWD=/Users/kpr/tmplocal/DUMS/zee
SHLVL=2
_=/usr/bin/printenv
/Users/kpr/nDoNotBackup/Dustin/srczee/Hey
/Volumes/oom/tmp/srczee/Hey
==========================================
2021-12-30 Thu 22:05:00
kpr
PATH=/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin
PWD=/Users/kpr
SHLVL=2
_=/usr/bin/printenv
/Users/kpr/nDoNotBackup/Dustin/srczee/Hey
find: /Volumes/oom/tmp: Operation not permitted
¿Por qué el cron puede causar este problema? ¿Cómo puedo ejecutar un comando tan simple como find
¿en cron, para que funcione igual que en el shell interactivo?
A continuación hay información sobre el HD externo y sobre el HD de mi macbook. ¿Tengo que formatear el HD externo de forma diferente? Pero entonces, ¿por qué es accesible desde la línea de comandos?
~/u/kh/bin> diskutil info /Volumes/oom
Device Identifier: disk4
Device Node: /dev/disk4
Whole: Yes
Part of Whole: disk4
Device / Media Name: My Passport 260D
Volume Name: oom
Mounted: Yes
Mount Point: /Volumes/oom
Content (IOContent): Apple_HFSX
File System Personality: Case-sensitive Journaled HFS+
Type (Bundle): hfs
Name (User Visible): Mac OS Extended (Case-sensitive, Journaled)
Journal: Journal size 385024 KB at offset 0x48c8000
Owners: Disabled
OS Can Be Installed: Yes
Booter Disk: disk3s3
Media Type: Generic
Protocol: USB
SMART Status: Not Supported
Volume UUID: 3FE9A430-BADA-39B9-8B8A-BBD9F734633D
Disk / Partition UUID: D1537CEC-27E9-43EF-86ED-E7A2A7A16C11
Disk Size: 5.0 TB (5000247902208 Bytes) (exactly 9766109184 512-Byte-Units)
Device Block Size: 512 Bytes
Volume Total Space: 5.0 TB (5000247902208 Bytes) (exactly 9766109184 512-Byte-Units)
Volume Used Space: 2.8 TB (2773301460992 Bytes) (exactly 5416604416 512-Byte-Units) (55.5%)
Volume Free Space: 2.2 TB (2226946441216 Bytes) (exactly 4349504768 512-Byte-Units) (44.5%)
Allocation Block Size: 8192 Bytes
Read-Only Media: No
Read-Only Volume: No
Device Location: External
Removable Media: Fixed
Solid State: Info not available
Virtual: Yes
This disk is a Core Storage Logical Volume (LV). Core Storage Information:
LV UUID: D1537CEC-27E9-43EF-86ED-E7A2A7A16C11
LVF UUID: 6C06FD6C-D00A-4953-AFC3-5D5908487D26
LVG UUID: E80D582C-0EDA-49E0-ADD6-A718B36AAF6A
PV UUID (disk): 70BC9B73-B6CC-4D90-9DC0-22EC0E5490D3 (disk3s2)
Fusion Drive: No
Encrypted: Yes
~/u/kh/bin> diskutil info /
Device Identifier: disk1s1
Device Node: /dev/disk1s1
Whole: No
Part of Whole: disk1
Volume Name: Macintosh HD
Mounted: Yes
Mount Point: /
Partition Type: 41504653-0000-11AA-AA11-00306543ECAC
File System Personality: APFS
Type (Bundle): apfs
Name (User Visible): APFS
Owners: Enabled
OS Can Be Installed: No
Booter Disk: disk1s3
Recovery Disk: disk1s4
Media Type: Generic
Protocol: PCI-Express
SMART Status: Verified
Volume UUID: 36033C28-202B-4932-B271-C8BD841FBAAF
Disk / Partition UUID: 36033C28-202B-4932-B271-C8BD841FBAAF
Disk Size: 2.0 TB (2000796545024 Bytes) (exactly 3907805752 512-Byte-Units)
Device Block Size: 4096 Bytes
Container Total Space: 2.0 TB (2000796545024 Bytes) (exactly 3907805752 512-Byte-Units)
Container Free Space: 1.2 TB (1209274347520 Bytes) (exactly 2361863960 512-Byte-Units)
Allocation Block Size: 4096 Bytes
Read-Only Media: No
Read-Only Volume: Yes
Device Location: Internal
Removable Media: Fixed
Solid State: Yes
Hardware AES Support: Yes
This disk is an APFS Volume. APFS Information:
APFS Container: disk1
APFS Physical Store: disk0s2
Fusion Drive: No
APFS Volume Group: 8D013C64-D366-4902-B782-502203E919F2
FileVault: Yes
Locked: No
~/u/kh/bin>
0 votos
Es posible que tenga que dar a cron acceso total al disco.
1 votos
¿La respuesta a "En Catalina, ¿cómo puede un cronjob obtener permiso para tocar archivos en un disco USB?" ¿resolver su problema?