|
Post by noname1112 on Mar 29, 2008 1:41:32 GMT 7
hi. i am currently using a desktop pc with an 200 gb drive and debian etch, to store all the data for my family. we use wol, to turn the pc on, and this script from this site, to turn it off. the pc looks in a specified ip range for running clients and shuts down after a specified time, if there are none. i like this solution, because you don't need to login to shutdown and you can't disconnect another client's connection by turning off the device. i would like to know now, whether there is a way to make this script work on the n5200 without installing debian. i want to keep the orignal os with its user-friendly gui. thanks noname1112
|
|
|
Post by gideon007 on Mar 29, 2008 2:28:55 GMT 7
Why don't you use the modules shutdown, sysuser, sshd (the latter twos are needed for shutdown)? With these installed on the Thecus, you just need to have your script execute a ssh connection to the Thecus as user shutdown and the Thecus will shutdown if it was turned on. For this to work you need to ssh connect once as user shutdown so the ssh hash is stored and the script doesn't stop on this step the first time it is run. The modules page is at onbeat.dk/thecus/index.php/N5200_Module_List
|
|
|
Post by noname1112 on Mar 29, 2008 4:09:06 GMT 7
thanks for the reply. if i realize your solution, a second device needs to search in the ip range of the network for clients and send the shutdown signal to the n5200 via ssh, if no clients were found. i don't want a computer to run the script due to its power consumption. perhaps, it's possible to run the script on my dd-wrt router and let my router send the shutdown signal. if not, i'll try openwrt.
thanks noname1112
|
|
|
Post by tenny321 on Mar 29, 2008 4:50:44 GMT 7
I would like something like this too. So far i have it where i can log into the SSH and from there i can reboot. Does anyone know the command in the n5200 that will shutdown the device? and no "shutdown" does not work.
I have tried to use the shutdown module but it does not work.
|
|
|
Post by noname1112 on Mar 29, 2008 5:45:50 GMT 7
this is what i have done so far: 1. telnet in dd-wrt router + login 2. run command "vi /tmp/powersaver.sh" 3.a) copy and paste the script in there 3.b) save it by typing ":wq" + enter 4. run command "chmod +x /usr/local/bin/powersaver.sh" to make the created file executable 5. run command "echo ' */10 * * * * root /tmp/powersaver.sh' >> /tmp/crontab" 6. restart crond with the command "stopservice cron && startservice cron" crond executes "powersaver.sh" 3 times (RETRIES=2) every 10 minutes (can be changed in /tmp/crontab). if it doesn't find any clients (MINCLIENTS=0), the command "shutdown -h now;" in the script will run. everything works so far. the file powersaver-status (STATUSFILE="/tmp/powersaver-status"), needed to count the attemps, is created. now, i have to find a way to make my dd-wrt router login in the n5200 via ssh and use the shutdown module. the howtos, i used: Homepage of the scriptdd-wrt cronATTENTION: you use the steps, i desribed above, on you own risk. i am not responsible for any damages. noname1112
|
|
|
Post by noname1112 on Mar 29, 2008 6:27:10 GMT 7
here is the manpage for openssh: Linkthe ssh login command must be something like: ssh root@192.168.1.50 (example) i think that this should be enough to login, if you don't use any authentification. but, i want to have some kind of security. i found this. Brianetta describes a way to use ssh with public/private key authentication (first method), that can be used to login without a password. I think that the second method can't be used in the dd-wrt without installing additional programs, which is difficult on most routers due to the lack of storage capacity. what do you think? is this a possible way for the dd-wrt router to login in the n5200? how should i further modify the script, in order to make the dd-wrt router login in the n5200 nas via nas and shut it down? noname1112
|
|
|
Post by noname1112 on Mar 29, 2008 8:21:24 GMT 7
i get this error in the telnet session of my dd-wrt router:
/tmp # ./powersaver.sh ./powersaver.sh: ./powersaver.sh: 29: nmap: not found Shutdown, my dear... ./powersaver.sh: ./powersaver.sh: 2: shutdown: not found
i'll try to install nmap on my v23sp2 micro.
|
|
|
Post by tenny321 on Mar 29, 2008 8:45:07 GMT 7
that is why i was asking what the shutdown command was. There is no shutdown command on the N5200's. There is a reboot. If anyone knows how to shutdown the N5200 while SSHed into the device let us know please This would help me out too. I seen something that the command "reboot -e" (or "restart -e") does it but i can not test right now since i am building my raid.
|
|
|
Post by noname1112 on Mar 29, 2008 18:58:05 GMT 7
hm. i always used "shutdown -h now" and don't know of another way. i can't check myself, because my raid is currently broken and my n5200 tries to rebuild it . i tried to install nmap on my dd-wrt router with its limited storage capacity. it didn't work. i'll expand the storage with a sd mod and try again. noname1112
|
|
|
Post by gideon007 on Mar 29, 2008 19:05:15 GMT 7
I don't get it. In your first post you mentioned that you are running a script. How and from what machine are you running that script and why can't that script not execute a simple ssh connection?
So there is already a script running or something else that looks for running clients and then shuts off. Why not insert the simple ssh command in between? Instead of "no clients -> shut down" make it go "no clients -> ssh -l shutdown -pw shutdown "IP of N5200" -> shut down"
@tenny if the module shutdown does not work for you, why don't you start a new thread asking for help, so we can try to trouble shoot you. It should work and does so for other users, including me and is the easiest solution.
|
|
|
Post by noname1112 on Mar 29, 2008 20:01:01 GMT 7
the script works on my debian etch desktop pc which is currently storing all my data. i wanted my n5200 to run the script, too. this way, the n5200 looks in a specified ip range for clients and shuts itself down, if none were found. gideon007 told me to use the shutdown, sysuser and sshd module to turn my n5200 off. but, i want some device to look for clients and handle the shutdown procedure without me interfering. perhaps, it is possible to make a dd-wrt router run the script and log in the n5200 and shut it down, if no clients were found in a specified ip range within a certain time. it is true that the dd-wrt router can build up a ssh connection to the n5200, if you don't use any authentification. but, i want some kind of security. afaik you can used password or/and public/private key authentication ( Link). if you use the password authentification, you have to use expect or type the password in. i want to use only the private/public key authentification, because i think that this is the easiest way for the dd-wrt router to login without me interfering. i can use my debian server to look for clients and shut my n5200 down via ssh. but, it consumes about 60 watt. i want to save power. therefore, i want my router to handle the job. an alternative way is the nslu2 with debian. it doesn't consume much electricity. noname1112
|
|
|
Post by gideon007 on Mar 30, 2008 2:12:18 GMT 7
ok, I see what you are aiming at now.
|
|
|
Post by tenny321 on Mar 30, 2008 4:29:27 GMT 7
Use the shutdown loggin thing but change the password. The shutdown command is missing from the OS on the N5200.
|
|
|
Post by noname1112 on Jun 7, 2008 4:58:37 GMT 7
i changed the script of marco gabriel. it uses now ping to search in the specified lan ip range for clients and turns the n5200 off after the specified number of retries using the command "halt". i used the shell command "vi" to create a file "powersaver.sh" in the directory "/usr/bin" and pasted the script. then, i made the script executable with the following command: "chmod +x /usr/bin/powersaver.sh" now. you have to make the n5200 execute "powersaver.sh" always after a specified time span (for example 10 minutes). execute "crontab -e" in a root shell first. then, paste the following using the "vi" commands: */10 * * * * /usr/bin/powersaver.sh my n5200 executed "powersaver.sh" every 10 minutes und turned itself off after 3 failed attempts. i booted the n5200 using wol. but, the n5200 deletes the "powersaver.sh" and revokes all the changes i made to the cron file. therefore, the n5200 won't shutdown automatically. does somebody know how to solve this problem? this is the only problem left. otherwise, the script works perfectly. the script: #!/bin/sh # # (cc:by-sa) 2007 Marco Gabriel, www.marcogabriel.com/# # Powersaver.sh ### # CONFIG ### # Filename of the statusfile STATUSFILE="/tmp/powersaver-status" # which ip range should be checked? # this example looks in "192.168.1.10 to 192.168.1.30" # example: # a=192.168.1. # b1=10 # b2=30 a=192.168.1. b1=10 b2=30 # how many clients are always on (other servers, routers, etc) MINCLIENTS=0 # shutdown after how many retries? RETRIES=2 ### # END CONFIG ### NUMCLIENTS=0 for((x=$b1;x<=$b2;x++)); do ping -c 1 $a$x if [ $? -eq 0 ]; then let NUMCLIENTS=$NUMCLIENTS+1 fi done if [ $NUMCLIENTS -le $MINCLIENTS ]; then if [ ! -f "$STATUSFILE" ]; then echo "COUNT=$RETRIES" > $STATUSFILE fi . $STATUSFILE if [ $COUNT -le $MINCLIENTS ]; then halt; else let COUNT=$COUNT-1 echo "COUNT=$COUNT" > $STATUSFILE fi; else if [ -f "$STATUSFILE" ]; then rm $STATUSFILE fi fi noname1112
|
|
|
Post by pellicle on Jun 7, 2008 5:50:31 GMT 7
Use the Meta module courtesy of Andreas and write a script to copy your file to the appropriate location. Sore a copy of the file in a folder in your raid array so it will be available after boot to copy.
I have found this works well to get around such an issue.
|
|