3

I am running a command in my shell. It works ok in the shell. I mean just in terminal. But i need it to be run from a script file. When i run it from a script, the file specified in one option of the command is not accessible. It gives the same error as if the path to file was incorrect. The path to the file in command and in script is absolute. I also tried different variations of the path - in root folder, with ~ in front, different absolute paths.

I created a script file, starting with #!/bin/bash and then the command on next line. Tried executing it like this:

sudo sh script.sh
sudo bash script.sh
sudo dash script.sh
. ./script.sh

Also tried changing first line to

#!/bin/bash
#!/bin/sh
#!/bin/dash
#!/bin/env sh
#!/bin/env bash
#!/bin/env dash

Tried combining ALL combinations of header line and run command. All with same results.

When running from script file, the file passed in an option is not accessible. But exactly same commmand works perfectly in shell. File is passed in option with absolute path, eg /home/ubuntu/file

I also got this output

ubuntu@ip-XXX-XXX-XXX-XXX:~$ file -h /bin/sh
/bin/sh: symbolic link to dash

ubuntu@ip-172-30-2-170:~$ file -h /bin/bash
/bin/bash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, 
BuildID[sha1]=452da38d6212b692cd80eb0dd1c99cf853da31ae, stripped

ubuntu@ip-172-30-2-170:~$ file -h /bin/dash
/bin/dash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, 
BuildID[sha1]=a783260e3a5fe0afdae77417eea7fbf8d645219e, stripped

upd: the command im running is the s3fs. A command to mount s3 bucket on AWS instance as a folder. I want to make it automount on instance start/reboot, and thinking of running the script with cron's @reboot

Here is it:

sudo /usr/local/bin/s3fs s3bucketname /home/ubuntu/bucketmountfolder -o allow_other -o uid=1000 -o mp_umask=002 -o multireq_max=5 -o use_path_request_style -o url=<myurl> -o passwd_file=/home/ubuntu/passwd

upd2:

i have solved the password file problem by removing the option and setting credentials in the default password file .passwd-s3fs. Now without password file option the command works fine with shell script, and NOT working in shell script file, same problem.

upd3:

my script file is like this:

#!/bin/bash
echo 'starting mount script'
sudo /usr/local/bin/s3fs s3bucketname /home/ubuntu/s3bucketmountfolder -o allow_other -o uid=1000 -o mp_umask=002 -o multireq_max=5 -o use_path_request_style -o url=<my url> -o dbglevel=info -f -o curldbg
echo 'mount script done'

Adding debug options to the command give such an output when run in script file:

ubuntu@ip-172-30-2-170:~$ . ./automount.sh
starting mount script
[CRT] s3fs.cpp:set_s3fs_log_level(297): change debug level from [CRT] to 
[INF]
[INF]     s3fs.cpp:set_mountpoint_attribute(4382): PROC(uid=0, gid=0) - 
MountPoint(uid=1000, gid=1000, mode=40775)
'use: unknown option `curldbg
mount script done

without debug options it is just like this:

ubuntu@ip-172-30-2-170:~$ . ./automount.sh
starting mount script
mount script done

In shell, command with debug options gives out about 50 lines of logs.

4
  • 1
    could you also please add the full error message ?
    – pLumo
    Sep 3, 2019 at 14:15
  • @pLumo there is no error message, no output, and adding debug options does not produce anything sensible. Just more errors. But ill add the output to question.
    – lxknvlk
    Sep 3, 2019 at 14:37
  • In your shell example the folder name is: /home/ubuntu/bucketmountfolder, while in the script example it is /home/ubuntu/s3bucketmountfolder, can this be the problem or do you have two folders?
    – JoeFox
    Sep 3, 2019 at 15:04
  • @JoeFox that is pseudocode, i have replaced sensitive names
    – lxknvlk
    Sep 4, 2019 at 12:25

1 Answer 1

4
'use: unknown option `curldbg

I suspect this line is the result of actually printing this:

fuse: unknown option `curldbg<CR>'

whereas <CR> is the carriage return character, causing the trailing apostrophe to overwrite the beginning of the line.

Make sure that your script contains Unix-style newlines (NL only).


Also note that

  • . ./script.sh (a.k.a. source ./script.sh),
  • bash ./script.sh (or any_other_shell ./script.sh),
  • ./script.sh

are three significantly different ways of invoking a script. Normally you should go with the third approach (along with an executable bit on the script). This is also the only one out of these three approaches where the #!/blah shebang line matters.

#!/bin/env sh

If you choose this approach for the shebang line, you need /usr/bin/env instead of /bin/env.

1
  • yes, the problem was with windows carriage returns in the script file. I have selected different line endings in Sublime text and it worked.
    – lxknvlk
    Sep 4, 2019 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .