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.