How to make custom script

KFL

Vu+ User
I make custom script test.sh. It worked in BH2091. Now in BH211 I take always error:
via ssh: sh: ./test.sh: not found
via gui: /bin/sh: /usr/script/test.sh: not found
File test.sh is in /usr/script and has 755 permissions. Same as other scripts: Uptime, Netstat, Ifconfig, Delete_all_crashlogs.
Restart of box did not solve problem.
Only mine script is not working, why? What are new special requirements? Whitelist?

test.sh
Code:
#!/bin/sh
#DESCRIPTION=Test script.
echo "Working."
exit 0
 
I make custom script test.sh. It worked in BH2091. Now in BH211 I take always error:
via ssh: sh: ./test.sh: not found
via gui: /bin/sh: /usr/script/test.sh: not found
File test.sh is in /usr/script and has 755 permissions. Same as other scripts: Uptime, Netstat, Ifconfig, Delete_all_crashlogs.
Restart of box did not solve problem.
Only mine script is not working, why? What are new special requirements? Whitelist?

test.sh
Code:
#!/bin/sh
#DESCRIPTION=Test script.
echo "Working."
exit 0

Use the appropriate editor for Linux
and try and via gui:
/usr/script/test.sh

shot1.jpg
 
Still not found
I think I have some other problem, cause I can not run script also from homedir or other location.
Perhaps some permission lost?
notfound.jpg
Code:
root@vuuno:/usr/script# echo "Working."
Working.
root@vuuno:/usr/script# test.sh
-sh: test.sh: not found
root@vuuno:/usr/script# ./test.sh
-sh: ./test.sh: not found
root@vuuno:/usr/script# ls -l
-rwxr-xr-x    1 root    root          125 Jul 24 22:04 Delete_all_Crashlogs.sh
-rwxr-xr-x    1 root    root          100 Jul 24 22:04 Ifconfig.sh
-rwxr-xr-x    1 root    root          115 Jul 24 22:04 Netstat.sh
-rwxr-xr-x    1 root    root            81 Jul 24 22:04 Uptime.sh
-rwxr-xr-x    1 root    root            61 Aug 24 00:21 test.sh
root@vuuno:/usr/script#
 
root@vusolose:~# /usr/script/test.sh
Working.

root@vusolose:~# /bin/sh: /usr/script/test.sh
-sh: /bin/sh:: not found
root@vusolose:~#
 
Perhaps some permission lost?

I do not know
I do not have that problem.


root@vusolose:/usr/script# ls -l
-rwxr-xr-x 1 root root 125 Jul 24 21:20 Delete_all_Crashlogs.sh
-rwxr-xr-x 1 root root 100 Jul 24 21:20 Ifconfig.sh
-rwxr-xr-x 1 root root 115 Jul 24 21:20 Netstat.sh
-rwxr-xr-x 1 root root 81 Jul 24 21:20 Uptime.sh
-rwxr-xr-x 1 root root 58 Aug 23 23:57 test.sh
root@vusolose:/usr/script#
 
Solved, but with trick. I have these files
Code:
root@vuuno:/usr/script# ls -l
-rwxr-xr-x    1 root    root          125 Jul 24 22:04 Delete_all_Crashlogs.sh
-rwxr-xr-x    1 root    root          100 Jul 24 22:04 Ifconfig.sh
-rwxr-xr-x    1 root    root          115 Jul 24 22:04 Netstat.sh
-rwxr-xr-x    1 root    root            81 Jul 24 22:04 Uptime.sh
-rwxr-xr-x    1 root    root            61 Aug 24 00:21 test.sh
-rwxr-xr-x    1 root    root          306 Aug 24 00:47 test2.sh
-rwxr-xr-x    1 root    root          312 Aug 24 00:46 test3.sh
root@vuuno:/usr/script#
test.sh - uploaded file via ftp (formating is ok) = not found
test3.sh - other file - not found
test2.sh - created with root@vuuno:~# cp /usr/script/Ifconfig.sh test2.sh
and then pasted code from test.sh or test2.sh = working

using cp => file will be executable
what permission is blocking this? Group/owner/... ? Give me hint = commands.
 
Way tu success:
1. copy existing script file to new file, e.g. cp /usr/script/Ifconfig.sh /usr/script/myscript.sh
2. open file for editing and paste new code, do not change format = do not delete empty lines (replace only main code)
3. save file
4. use script (green->blue->run)
 
Way tu success:
1. copy existing script file to new file, e.g. cp /usr/script/Ifconfig.sh /usr/script/myscript.sh
2. open file for editing and paste new code, do not change format = do not delete empty lines (replace only main code)
3. save file
4. use script (green->blue->run)


it can
But your problem is your editor
You must use the Unix (LF only) for editing
or you have to convert file after to the Unix .
 
Sorry, LF or CR/LF does not matter. Problem is, that file is not found.
I try reinstall image and give you info.
 
Sorry, LF or CR/LF does not matter. Problem is, that file is not found.
I try reinstall image and give you info.

I've verified a similar problem... in telnet I change my position in /usr/script ; trying launch a script the result is "not foundo" either the "ls" command showes the script; launching same script writing also absolute path all works fine.
See below what I've described:
root@bm750:/#
root@bm750:/# cd /usr/script
root@bm750:/usr/script# ls
Activity.sh HostName.sh System.sh
....... ecc ecc
root@bm750:/usr/script# HostName.sh
-sh: HostName.sh: not found
root@bm750:/usr/script# /usr/script/HostName.sh
bm750
root@bm750:/usr/script#
 
Ups, I made something wrong by uploading file or what, I really don't now where I made mistake.
Today I can not replicate my wrong steps. I started from scratch.

It is true: file format must be saved with LF only (Linux format).

Easy way to correct formating is to use command dos2unix. Now script works.
Code:
root@vuuno:/usr/script# ./test.sh
-sh: ./test.sh: not found
root@vuuno:/usr/script# ls -l
-rwxr-xr-x 1 root root 61 Aug 27 22:26 test.sh
root@vuuno:/usr/script# dos2unix test.sh
root@vuuno:/usr/script# ./test.sh
Working.
root@vuuno:/usr/script#
Problem is with showing incorrect line ends. For showing incorrect line ends "^M" use vi editor or editing F4 inside mc (midnight commander) (or simply use dos2unix).

Thank you for your patience, thank you for help.
 
Last edited:
Back
Top