Running and Creating Scripts From Code Found (The How to?)


Recommended Posts

Hey all.  I just setup my box recently and have been finding a bunch of different add-ons and scripts from other members here.  Any of the scripts that I have been able to download into a file, I can run from telnet just fine.  My problem when I make a script file with the code I found that users made I can't seem to run on telnet. 

 

For example I am trying to make a script for the install of the PS3 Media Server and the ls -R code.

 

For the ls -R I made a file named "ls-r" and copied the code from the ls -R thread.  Then from telnet I go the directory where it is located and type ls-R on telnet.  I get

root@Tower:/boot# ls-r

-bash: ls-r: command not found

  Am I not doing something right such as an extra command I have to put on the telnet console in order for me to run this.

The Filename Is ls-r (or ls-r.sh, I tried both) and whats written in the file:

#!/bin/sh
# Edit as needed, if user shares not used, then list /mnt/disk1, /mnt/disk2, etc.
#shared_drive="/mnt/user"
#shared_drive="/mnt/user/Movies /mnt/user/Mp3 /mnt/user/Pictures"
shared_drive="/mnt/disk1/Videos1 /mnt/disk2/Videos2 /mnt/disk3/Videos3 /mnt/disk3/VidLib3 /mnt/disk4/Videos4 /mnt/disk4/VidLib4 /mnt/disk5/Videos5 /mnt/disk6/Videos6 /mnt/disk7/Videos7"

crontab -l >/tmp/crontab
grep -q "frequent ls" /tmp/crontab 1>/dev/null 2>&1
if [ "$?" = "1" ]
then
    echo "# frequent ls to keep directory blocks in memory:" >>/tmp/crontab
    echo "* * * * * ls -R $shared_drive 1>/dev/null 2>&1" >>/tmp/crontab
    crontab /tmp/crontab
fi

 

The same thing happened for the PS3 server in which I made a file named ps3 and tried running it.

Filename: ps3.sh, Whats written in the file:

cd /boot/custom/usr/share/packages
installpkg jre-6u11-i586-1.tgz
cd /boot/custom/usr/share/packages/mencoder
installpkg *.tgz
cd /boot/custom/usr/share/packages/pms
./PMS.sh

The console respons:

root@Tower:/boot/scripts# ps3.sh

: No such file or directory/custom/usr/share/packages

: package does not end in .tgz.tgz

: No such file or directory/custom/usr/share/packages/mencoder

: package does not end in .tgz

: No such file or directory/custom/usr/share/packages/pms

: No such file or directory

 

If I take the code and paste it onto telnet it runs perfectly find but when I try running it through a file I get errors.  Is there something I am doing incorrectly?  Any help would be great thanks.

 

Link to comment

Hey all.  I just setup my box recently and have been finding a bunch of different add-ons and scripts from other members here.  Any of the scripts that I have been able to download into a file, I can run from telnet just fine.  My problem when I make a script file with the code I found that users made I can't seem to run on telnet. 

 

For example I am trying to make a script for the install of the PS3 Media Server and the ls -R code.

 

For the ls -R I made a file named "ls-r" and copied the code from the ls -R thread.  Then from telnet I go the directory where it is located and type ls-R on telnet.  I get

root@Tower:/boot# ls-r

-bash: ls-r: command not found

  Am I not doing something right such as an extra command I have to put on the telnet console in order for me to run this.

The Filename Is ls-r (or ls-r.sh, I tried both) and whats written in the file:

#!/bin/sh
# Edit as needed, if user shares not used, then list /mnt/disk1, /mnt/disk2, etc.
#shared_drive="/mnt/user"
#shared_drive="/mnt/user/Movies /mnt/user/Mp3 /mnt/user/Pictures"
shared_drive="/mnt/disk1/Videos1 /mnt/disk2/Videos2 /mnt/disk3/Videos3 /mnt/disk3/VidLib3 /mnt/disk4/Videos4 /mnt/disk4/VidLib4 /mnt/disk5/Videos5 /mnt/disk6/Videos6 /mnt/disk7/Videos7"

crontab -l >/tmp/crontab
grep -q "frequent ls" /tmp/crontab 1>/dev/null 2>&1
if [ "$?" = "1" ]
then
    echo "# frequent ls to keep directory blocks in memory:" >>/tmp/crontab
    echo "* * * * * ls -R $shared_drive 1>/dev/null 2>&1" >>/tmp/crontab
    crontab /tmp/crontab
fi

 

Most likely it is this: http://lime-technology.com/wiki/index.php?title=FAQ#Why_do_my_scripts_have_problems_with_end-of-lines.3F

 

Joe L.

The same thing happened for the PS3 server in which I made a file named ps3 and tried running it.

Filename: ps3.sh, Whats written in the file:

cd /boot/custom/usr/share/packages
installpkg jre-6u11-i586-1.tgz
cd /boot/custom/usr/share/packages/mencoder
installpkg *.tgz
cd /boot/custom/usr/share/packages/pms
./PMS.sh

The console respons:

root@Tower:/boot/scripts# ps3.sh

: No such file or directory/custom/usr/share/packages

: package does not end in .tgz.tgz

: No such file or directory/custom/usr/share/packages/mencoder

: package does not end in .tgz

: No such file or directory/custom/usr/share/packages/pms

: No such file or directory

 

If I take the code and paste it onto telnet it runs perfectly find but when I try running it through a file I get errors.  Is there something I am doing incorrectly?  Any help would be great thanks.

 

Link to comment

Notepad2 is a free windows text editor that can properly edit linux files and color codes text in config files.

 

http://www.flos-freeware.ch/notepad2.html

 

It, PuTTy, and 7-zip are the three tools I recommend to Windows users who want to start tinkering with their unRAID system.

 

For editing text inside the terminal, nano is great. It's much easier for beginners to use than vi. You could make a new blank PMS.conf file with it, copy & paste over the old contents, and save it for a properly formatted file.

 

http://packages.slackware.it/package.php?q=current/nano-2.0.9-i486-1

Link to comment

Linux, unlike DOS, does not by default include the current directory in the path it searches for programs.

 

If you want to execute a program ls-r that is a file in the  current directory, you have to use:

 

./ls-r

 

meaning run the file ls-r that is in the current directory.

 

You also have to make the file "executable" when you create it, by the command:

 

chmod +x ls-r

Link to comment

As others have said there is more then likely a problem with the line feed.

 

I use a free program called Editpad Lite that allows me to switch back ad forth between Unix, Mac OS and Windows OS style formats.  The other cool thing about Editpad Lite is that it can do tabbed editing.  You do not have to have multiple windows open which save a lot on space on a small monitor.

Link to comment

Don't forget to edit the shared_drive line.  The one above is what I use, and will not help you at all.  The 2 that begin with a pound symbol (means they are commented out and being ignored) are there as an example.  You will need to tailor the line you want, to include the folders you want to keep cached.

Link to comment
  • 7 months later...

Linux noob... (On a Windows 7 x64 system.)

 

Using Notepad++ and setting it to [Format] -> Convert to UNIX.

 

Copied and pasted some code (setup_anon_shares.sh to be exact [http://lime-technology.com/forum/index.php?topic=2098.0]) and then copied the file into my flash drive.

Executing it, I keep getting -bash: ./anonymous.sh: cannot execute binary file

 

Tried running the fromdos command (http://lime-technology.com/wiki/index.php?title=FAQ#Why_do_my_scripts_have_problems_with_end-of-lines.3F) but still no luck.

Tried chmod to make it executable (http://lime-technology.com/wiki/index.php?title=FAQ#How_is_a_Linux_console_different_from_a_Windows_console.3F).

 

Copying & pasting the contents of the file into telnet seems to work since I can now map the shares anonymously.

 

Did a search for that error but nothing specific on the unRAID forums. Google has results for other Linux builds...

 

Any help is appreciated.

Link to comment

Thanks. It's just code copied and pasted into a text file...

There are three "binary" characters at the start of the first line in the file.

 

To see them type:

root@Tower:/boot# od -c anonymous.sh | head

0000000 357 273 277  #  !  /  b  i  n  /  b  a  s  h  \n  #

0000020  \n  #      T  i  t  l  e  :      s  e  t  u  p  _

0000040  a  n  o  n  _  s  h  a  r  e  s  .  s  h  \n  #

0000060  \n  #      S  u  m  m  a  r  y  :  \n  #      U  s

0000100  e      t  h  i  s      s  c  r  i  p  t      t  o

0000120      e  n  a  b  l  e      a  n  o  n  y  m  o  u

0000140  s      a  c  c  e  s  s      t  o      p  r  e  -

0000160  c  o  n  f  i  g  u  r  e  d      S  M  B      s

0000200  h  a  r  e  s  .          T  h  e      s  c  r  i

0000220  p  t      w  i  l  l  \n  #      e  n  a  b  l  e

 

To remove them, type "mc" to invoke midnight commander, use its editor to edit the file, delete the three characters and re-save the file.

I normally would use the "vi" editor, but even it would not edit the file.

 

Oh yes, if you are using any recent version of unRAID the name of the config file for samba was changed...  you'll need to edit the script to change the name of the file being configured... otherwise you'll get this:

root@Tower:/boot# anonymous.sh

awk: cmd. line:3: fatal: cannot open file `/etc/samba/smb.shares' for reading (No such file or directory)

 

To help, attached is a fixed, improved version.  It automatically uses the correct samba file and it also allows you to specify the share list on the command line.  That means you do not need to edit the command at all, you can simply invoke it with the "-s" parameter.

 

Also, the original version did not properly deal with share names with spaces, dashes, or undescores (anything other than alpha) and put the guest ok in the wrong spot when there were multiple shares with the same sub-string.  I have "Movies", "Movies A-D" "Movies E-J", Movies K-O", etc.  It put the "guest ok" in "Movies_New" (the first share after the one I had that did not have an embedded space)  When I fixed that problem it then incorrectly matched all the "Movies*" on the sub-string... I fixed that too. It now matches explicitly the share name, not just looking for it as a sub-string of the share name.

 

I've added a few lines sent to the screen showing what it does when it does it... They will help you to know it worked as intended.

 

The usage is:

anonymous.sh

or

anonymous.sh -s "Movies|Pictures|TV"

If you do not supply a share list using the "-s" option, it will default to "Movies|TV"

 

You can also type

anonymous.sh -v

to see the current version (I made this version 1.1)

 

Joe L.

 

Link to comment

Those three characters are likely the Unicode BOM (Byte-Order-Mark).

 

http://unicode.org/faq/utf_bom.html#BOM:

A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may be mandatory (or prohibited) in the Unicode data stream defined in that protocol

 

Link to comment

You can also type

anonymous.sh -v

to see the current version (I made this version 1.1)

 

Joe L.

 

Thank you Joe L! I'll try it out.

(Now to read up on Samba and make those shares read-only.)

 

This should probably be posted into the FAQ for "Tweaks & Enhancements" (I've linked to this post in the thread.)

http://lime-technology.com/wiki/index.php?title=Best_of_the_Forums#Tweaks_and_Enhancements

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.