Jump to content

[SOLVED] How to create a *.sh SCRIPT file


Recommended Posts

Hello,

 

how can i create a *.sh file?

I´m a linux newbie & my english is verry rusty, because i´m a german user.

 

I tried a few times to copy and paste text to a wordpad editor for a s3 sleep script.

On bootup unraid says "bad interpreter ect ect..."

 

Google says to use a notepad++ and than save the file as an *.sh with a sh structure.

 

When i copied to unraid, i log in on telnet and type chmod +x s3.sh to make it executable.

Then reboot.

On bootup unraid say´s "bad interpreter ect ect...".

 

Where are my mistakes?

What is the easy´s way to make a script?

Link to comment

Also do yourself a favor and check your script with the mc command because I noticed sometimes you will fined a ^M in your code if it isn't saved right.

 

I had the same problem a few nights ago and it made me crazy until I realized it was just because there was some hidden characters.

Link to comment

What are the contents you put in this script?

 

The S3 Sleep script...

 

----------------------------------------------

#!/bin/bash

 

drives="/dev/sda /dev/sdb"

timeout=5

 

 

count=5

while [ 1 ]

do

  hdparm -C $drives | grep -q active

  if [ $? -eq 1 ]

  then

    count=$[$count-1]

  else

    count=$timeout

  fi

  if [ $count -le 0 ]

  then

    # Do pre-sleep activities

    sleep 5

 

    # Go to sleep

    echo 3 > /proc/acpi/sleep

 

    # Do post-sleep activities

    # Force a DHCP renewal (shouldn't be used for static-ip boxes)

    /sbin/dhcpcd -n

    sleep 5

 

    count=$timeout

  fi

  # Wait a minute

  echo COUNT $count

  sleep 60

done

-----------------------------------------------------------------------

 

Link to comment

What are the contents you put in this script?

 

The S3 Sleep script...

 

----------------------------------------------

#!/bin/bash

 

drives="/dev/sda /dev/sdb"

timeout=5

 

 

count=5

while [ 1 ]

do

  hdparm -C $drives | grep -q active

  if [ $? -eq 1 ]

  then

    count=$[$count-1]

  else

    count=$timeout

  fi

  if [ $count -le 0 ]

  then

    # Do pre-sleep activities

    sleep 5

 

    # Go to sleep

    echo 3 > /proc/acpi/sleep

 

    # Do post-sleep activities

    # Force a DHCP renewal (shouldn't be used for static-ip boxes)

    /sbin/dhcpcd -n

    sleep 5

 

    count=$timeout

  fi

  # Wait a minute

  echo COUNT $count

  sleep 60

done

-----------------------------------------------------------------------

 

Odds are good you have carriage returns at the ends of the lines and the server is looking for "/bin/bash^M" which does not exist.
Link to comment

I have download these text from this forum.

 

I copy and paste it to notepad++ and save it to s3.sh

 

What should i do with script text from this forum to make it executable?

 

What can i do? I´m a linux newbie.

 

Where can i read step by step instructions how to do?

 

It makes me want to tear my hair out! :o  ???

 

 

 

 

Link to comment

No one?  >:(

 

With the fromdos -a comand ?

 

i find on google :

 

"Always convert. If converting from DOS to Unix, this option will cause the program to remove ALL carriage returns. The default is to remove carriage returns only if they are followed by line feeds. If converting from Unix to DOS, this option will cause the program to convert ALL linefeeds to carriage return pairs. The default is to convert linefeeds only if they are not already preceded by a carriage return."

 

On Example: fromdos -a s3.sh?

Must i type this command in the go file before the s3.sh starts?

Or must i type fromdos -a s3.sh command on telnet, then reboot, ONE TIME (saveproof),or every time before unraid starts?

 

Please dont forgett, i am a linux / unraid rookie...

Link to comment

My solution was to do all my editing in "vi" which is native to the OS.

 

There are a number of text editor available, my favourite being vi. Now I am cheating since I us vi at my job, and have for years, but it does remove all chance of messing things up doing 'conversions'.

 

There are other options, and the web is a rich resource to find information about the alternative text editors.

 

This is kind of a 'when in Rome...' solution, but you may find it a good one. If you are ready to dive into shell scripting so early in your unRAID experience then you must be ready for vi also.  ;)

 

Hope this helps.

 

Bruce

Link to comment

Open a telnet session to your server and use the command "mc" to browse through your directory structure.

 

Go to the location of your script and press "F4" to edit it. Press "F12" and choose "Linux Format (LF)".

 

File is saved now in the correct format.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...