Problem with 'ln' in a shell script

I've 2 systems, one running Mate 20.04 and the other Ubuntu 18.04. Both are set up in a similar fashion and I use pCloud to synchronise my documents across both devices. On both desktops I have a symlink to a folder called 'Work Dump' which points to a folder in pCloud where I keep the documents that I'm currently working on.

Because my pCloud partition is only mounted after I decrypt a Veracrypt partition I need to recreate the symlink to Work Dump on each boot. This works perfectly at the end of my auto-run script in Ubuntu 18.04 by having

ln -sfn "/home/me/pCloudDrive/path/Work Dump" "/home/me/Desktop/Work Dump"

as the final line in my script.

However this doesn't work in Mate 20.04. To try and isolate the problem I've created a seperate script to run on start-up so that I can work directly on solving it. The script (in full) is

#!/bin/sh

pcloud_dir=/home/me/pCloudDrive
while true
do
if [ -d "$pcloud_dir" ]
then
echo pCloud folder is ready
break
else
echo pCloud folder not available
fi
sleep 10
done

echo DO pCloud STUFF HERE
ln -sfn "/home/me/pCloudDrive/path/Work Dump" "/home/me/Desktop/Work Dump"

This doesn't refresh the symlink on start-up. However when I run the script manually it works fine. Other items in my auto-run script (calling Veracrypt, triggering pCloud once Veracrypt mounted) work fine on both systems and the refreshing the symlink works fine on Ubunt 18.04.

Hi @echo59 :slight_smile:

If it run perfectly when you run it manually and not automatically, i guess it can be related to env variables.
Try to send output of env command from the top of the script to a temporary file, back it up and next manually run it to compare the difference in the temp files.

Good luck :slight_smile:

Thanks @olek ran ENV and the outputs of both are listed below with differentials highlighted.

1 Like

I do not have programming experience, so just guessing; could it be that script running earlier than the decrypted devices are available (20.04 may be doing more stuff than 18.04) or some permission issue for the script that is not an issue when you are manually running it? If you enable logging does it show something?

1 Like

Thanks @saivinob. I've dealt with that in 2 ways. First, I've delayed the script for a period of time at start-up. Second, the first part of the script is a loop that only progresses to running the 'ln' command once the path to the target folder exists.

2 Likes

Hi echo,
Did you obviously updated Veracrypt last version? In Focal 20.04 is necessary required to be updated.
Cheers

Thanks @Tim. It's VeraCrypt 1.24-Update7 (released 07 August 2020). Also pCloud is currently 1.8.7.

@saivinob logging with

exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/home/me/Desktop/log_xxx.txt 2>&1

revealed nothing other than the output from the 'echo' lines when run both manually and at start-up.

@echo59, I'm afraid I can't be of help wrt codes. I did not get head or tail of the code you mentioned :grin:. That said, I try to help others by just asking some questions that may be obvious but many times missed. I still think it is possible your drive is not ready by the time link command runs or there is problem with permissions when run from script.

Two more questions, :smiley:

  1. When you say it works when the script is run manually, does it ask for any password for you to input? If so, may be the password method you put in your script is not working.

  2. Why do you even have command to create symlink in the script? Once a link is created, doesn't it work whenever the source is available?
    What I mean is, to test I created a folder by name 'test' and a link 'linktest' pointing to 'test' folder. When I deleted the folder, the link shows in red (broken) but if I recreate the folder 'test' the link works fine. So, if you created a link for work dump from pCloud in you home directory, doesn't it activate when the drive is mounted via script? Is it really getting decrypted/mounted via script?

1 Like

Thanks @saivinob. Went back and worked the problem. I've increased the time intervals and went for coffee. Low and behold when I came back the symlink was recreated!!!!!

Now, my script is set to run after a 100 second delay (the max) and the first command is SLEEP for 2 minutes...

#!/bin/sh

sleep 120

pcloud_dir=/home/me/pCloudDrive
while true
do
if [ -d "$pcloud_dir" ]
then
echo pCloud folder is ready
break
else
echo pCloud folder not available
sleep 10
fi
done

sleep 60

echo DO LN STUFF HERE
ln -sfn "/home/me/pCloudDrive/Dropbox/Active Jobs/aaa To Do/Active Directory/Work Dump" "/home/me/Desktop/Work Dump"
echo LN STUFF IS DONE

It takes a while but it works.....

Thanks for your perseverence. I 'thought' that I'd allowed enough time but obviously not!

3 Likes

What a clever solution, glad that you figured it out

1 Like