Script running as root gives weird error

I have written a little script that backs up the symlinks for a user into a .txt file:

#!/bin/bash

# this script simply checks for symlinks in a users directory, and saved it as a .txt file. This is purely for when we have
# to do a recover of the server.

USERS=$(/usr/local/hestia/bin/v-list-users plain | awk '{print $1}')

for user in $USERS; do

	echo "BLA: $user"

	output=$(cd /home/$user/ && find . -maxdepth 10 -type l -ls)
	echo "$output" > /home/$user/symlinks.txt

done

This works fine when run manually, but on cron with:

5 * * * * bash /root/symlink-backups-per-user.sh

I get:

/usr/local/hestia/bin/v-list-users: line 17: /func/main.sh: No such file or directory
/usr/local/hestia/bin/v-list-users: line 112: /data/users/admin/user.conf: No such file or directory
/usr/local/hestia/bin/v-list-users: line 112: /data/users/camping/user.conf: No such file or directory

What am I doing wrong?

Thanks!

Andy

The $HESTIA variable is probally not set
HESTIA="/usr/local/hestia/"

1 Like

Ah that looks like it. Although, it actually wanted:

HESTIA="/usr/local/hestia"

(i.e not the /bin)

Seems to runt through fine now :slight_smile: (I’m just waiting for the cron to double check)

1 Like

You are right

Hmm the cron just ran, but same error. This is my script:

#!/bin/bash

# this script simply checks for symlinks in a users directory, and saved it as a .txt file. This is purely for when we have
# to do a recover of the server.

HESTIA="/usr/local/hestia"
USERS=$(/usr/local/hestia/bin/v-list-users plain | awk '{print $1}')

for user in $USERS; do

	echo "BLA: $user"

	output=$(cd /home/$user/ && find . -maxdepth 10 -type l -ls)
	echo "$output" > /home/$user/symlinks.txt

done

Do I need to store the path somewhere else maybe?

FWIW, I got it going with:

#!/bin/bash

export HESTIA='/usr/local/hestia'
USERS=$(/usr/local/hestia/bin/v-list-users plain | awk '{print $1}')

for user in $USERS; do

	echo "BLA: $user"

	output=$(cd /home/$user/ && find . -maxdepth 10 -type l -ls)
	echo "$output" > /home/$user/symlinks.txt

done

The important part was “export”, so that the script exports the path into the cron envs ready to use. It now runs fine :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.