Solved how to run sh script when logged in as a root

Xampp Apache
June 19, 2013 at 03:53:49
Specs: linux kali
Hi!
I tried to run the following script from root (file saved at root ) and i am logged as root.
#!/bin/sh
echo "deb http:// deb.torproject.org/ torproject.org wheezy main" >> /etc/apt/ sources.list clear scr echo "[*] Installing the keys...." gpg --keyserver keys.gnupg.net --recv 886DDD89 gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - echo "Ready!!" clear scr echo "[*] Updating Repositories...." apt-get update clear scr echo "[*] Installing TOR" apt-get install deb.torproject.org- keyring apt-get install tor echo "Ready!!" echo "[*] Installing Vidalia" apt-get install vidalia echo "Ready!!" echo "[*] Installing iceweasel-torbutton" apt-get install iceweasel- torbutton echo "Ready!!" clear scr echo "[*] Installing Privoxy" apt-get install privoxy echo "[*] Configuring privoxy" echo "forward-socks5 / 127.0.0.1:9050 ." >> /etc/ privoxy/config echo "Ready!!" service tor restart service privoxy restart echo "Tor has been installed successfully."

When i save this script at root with a name like torinstall.sh and chmod +x it by
#chmod +x torinstall.sh
then #./torinstall.sh gives me "no such file or directory" what is the reason?


See More: how to run sh script when logged in as a root

Report •

✔ Best Answer
June 20, 2013 at 10:10:40
Hi:

Linux terminates each line with a line feed while Windows uses a carriage return/line feed to terminate each line.

With an error like this:

bash: ./tor.sh: /bin/sh^M: bad interpreter

It looks like you created this script on windows and moved it to Linux leaving the CR from windows. Verify this by editing your script with the vi editor. You should see each line with a ^M at the end.

Remove this while in vi or you can use the dos2unix command to remove them. There are also shell scripts available that will do it.



#1
June 19, 2013 at 04:26:12
If you run ls -asl, do you see it listed where you saved it?

How do you know when a politician is lying? His mouth is moving.


Report •

#2
June 19, 2013 at 04:53:36
yes it is listed in root, otherwise chmod command would have returned "no such file or directory"

Report •

#3
June 19, 2013 at 05:17:48
What about

sh torinstall.sh

Does that work?


Report •

Related Solutions

#4
June 19, 2013 at 08:04:03
yep, but only echo and other command runs without any installations i.e. apt-get install ...
Furthermore, i would like to inform, that kali is live on non persistent usb.

Report •

#5
June 19, 2013 at 09:20:01
Ah, I didn't notice that you were running a penetration-testing distribution. In that case I'll leave you to it as those setups can be strange.

You might like to check that /bin/sh is the path to sh on your setup.


Report •

#6
June 19, 2013 at 10:11:05
not at all; not only tor can be analysed but also IDS or honeypot logs when someone scans via tor or other vpn/proxy ; even tor was present on previous version "backtrack".

I have tried the script on btr2 with sudo removed but same result.

/bin/sh is an executable representing the system shell . Actually, it is usually implemented as a symbolic link pointing to the executable for whichever shell is the system shell. The system shell is kind of the default shell that system scripts should use.
so are you suggesting to change location of file torinstall.sh and then try?


Report •

#7
June 19, 2013 at 10:43:58
I know what sh is. I'm just trying to ascertain that on your system /bin/sh represents a real executable program. If it didn't you would get the result you detail. You know that the script file exists, so it's difficult to see what other file the message refers to. If any orher file were missing you should at least expect some output other than the error.

You say that /bin/sh is usually implemented as a link. So what does that link point on your system?


Report •

#8
June 19, 2013 at 18:40:33
You would be better off running Kali in a VM. I ran backtrack on a Live CD or USB & if the FAT32 partition or whatever it was wasn't persistent, it would lack certain properties.

How do you know when a politician is lying? His mouth is moving.


Report •

#9
June 19, 2013 at 18:51:36
this is turning to theoritical dicussion.
Let me provide you with more details:
i was able to run the script once (i don't remember how) .But next day when i rebooted live usb and then the problem started (since linux on usb is non persistent type so i need to run the script again).

i have tried all tricks like using chmod 775 instead of +x and running individual lines of the script at root,which is running,hence there is no problem in syntax of script.
But when i run it as sh torinstall.sh the script runs upto
echo "deb http:// deb.torproject.org/ torproject.org wheezy main" >> /etc/apt/ sources.list
clear scr
echo "[*] Installing the keys...." gpg --keyserver hkp://wwwkeys.us.pgp.net --recv 886DDD89 gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - echo "Ready!!" clear scr echo "[*]
then it completely skips updating and installation commands.


Report •

#10
June 19, 2013 at 19:14:00
As suggested by guapo earlier, persirtence attained by simply selecting some space during live usb installation by software like universal-usb-creator etc. is not working it results in lot of inode reference errors during next boot (even after some some simple installations).

I found something new and I am going to try it (since I dont want to leave usb medium) i.e.creating proper partitions on usb by linux commands (you need running ubuntu linux os).

I have heard it is the best way and by this way persistence really persists, even on usb.


Report •

#11
June 19, 2013 at 19:58:48
Another choice is a virtual machine.

How do you know when a politician is lying? His mouth is moving.


Report •

#12
June 19, 2013 at 23:18:03
Why the "sudo" if you are running as root?

Report •

#13
June 20, 2013 at 00:11:23
instead of pasting my script i pasted the original one from internet.

if you are trying to run it then keyserver "keys.gnupg.net" is not working and you need to replace it with "hkp://wwwkeys.us.pgp.net"

sudo is not there (i have mentioned earlier) . Let me assure you that individual commands of my script are running fine in root i.e tor is installed and up,but whole script is not.


Report •

#14
June 20, 2013 at 09:02:58
ok forget everything, here is a script to install tor on backtrack 5R2:

#!/bin/sh
echo "deb http://deb.torproject.org/torprojec... lucid main" >> /etc/apt/ sources.list
clear scr
echo "[*] Installing the keys...." gpg --keyserver hkp://wwwkeys.us.pgp.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
echo "Ready!!"
clear scr echo "[*] Updating Repositories...."
apt-get update
clear scr
echo "[*] Installing TOR"
apt-get -y install tor tor-geoipdb
echo "Ready!!"
clear scr
echo "[*] Installing Privoxy"
apt-get -y install privoxy echo "[*] Configuring privoxy"
echo "forward-socks4a / 127.0.0.1:9050 ." >> /etc/ privoxy/config
echo "Ready!!"
service tor restart
service privoxy restart
echo "Tor has been installed and ready to use."

I name it tor.sh and save it at root of live usb with bt5r2
then i use
chmod 775 tor.sh
(no error permission are changed)
then I give
./tor.sh

the exact error is "bash: ./tor.sh: /bin/sh^M: bad interpreter: No such file or directory"

so, please suggest how to run it?


Report •

#15
June 20, 2013 at 10:10:40
✔ Best Answer
Hi:

Linux terminates each line with a line feed while Windows uses a carriage return/line feed to terminate each line.

With an error like this:

bash: ./tor.sh: /bin/sh^M: bad interpreter

It looks like you created this script on windows and moved it to Linux leaving the CR from windows. Verify this by editing your script with the vi editor. You should see each line with a ^M at the end.

Remove this while in vi or you can use the dos2unix command to remove them. There are also shell scripts available that will do it.


Report •

#16
June 20, 2013 at 14:10:21
hkp://wwwkeys.us.pgp.net <-----hkp ??
- - - ----------------

How do you know when a politician is lying? His mouth is moving.


Report •

#17
June 20, 2013 at 18:18:04
Ok nails,I will try and remove ^M and then run it.

Yes guapo its "hkp://"
Horowitz's keyserver was called the HKP Keyserver after a web-based OpenPGP HTTP Keyserver Protocol (HKP).
It used to allow people to interact with the keyserver. Users were able to upload, download, and search keys either through HKP on port 11371, or through web pages which ran CGI scripts.


Report •

#18
January 18, 2014 at 03:42:58
Just open torinstall.sh in VIM go to Edit-File settings-File format-Unux and save

Report •

Ask Question