LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 10-03-2012, 02:30 AM   #1
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 34

Rep: Reputation: 16
script for samba to run to shutdown server?


I have a samba share called "shutdown". I want to write a script that is run when that share is logged into that will shutdown my server. I regularly view movies using my xbox and don't want to have to walk into my living room to shutdown my server. (RPC stuff from client is not an option)

sys specs:
Debian Squeeze
samba 3.5.6

No matter what bash script I write, I can't get it done. Can someone help me?
 
Old 10-03-2012, 02:48 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 50
Why don't you use ssh to shutdown server. It is quite easy.
 
Old 10-03-2012, 03:21 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Quote:
Originally Posted by pavi_kanetkar View Post
Why don't you use ssh to shutdown server. It is quite easy.
Because there are no good SSH clients for the Xbox.

@Hailey's_Comet: You don't even need a separate share for this. Copy a small mp3 file to your normal share and call it shutdown.mp3, so that you can open it with the Xbox. Now you can use inotify to wait for that file to be opened by you and use that event to shutdown the system.
 
Old 10-03-2012, 02:00 PM   #4
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 34

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by pavi_kanetkar View Post
Why don't you use ssh to shutdown server. It is quite easy.
Because I am trying to get this done with the ability to use ANYTHING that can access a simple samba share. I am currently writing this from a laptop logged into my server with XDMCP tunneled in SSH, which is beyond mere SSH. I have a myriad of means already, I just want one more.

Besides, if I can get it done it will be the end to a long project.
 
Old 10-03-2012, 02:10 PM   #5
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 34

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by TobiSGD View Post
Because there are no good SSH clients for the Xbox.

@Hailey's_Comet: You don't even need a separate share for this. Copy a small mp3 file to your normal share and call it shutdown.mp3, so that you can open it with the Xbox. Now you can use inotify to wait for that file to be opened by you and use that event to shutdown the system.
"inotify" would be lovely, I will make a utility from example code from http://www.thegeekstuff.com/2010/04/...ogram-example/. I would, however, like a bash script alternative to make it more portable.
 
Old 10-03-2012, 02:28 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Code:
inotifywait -e access /path/to/the/monitored/file
will wait for the file to be accessed and return with exit-code 0 if the event occurs. So a script like this
Code:
#!/bin/bash
inotifywait -e access /path/to/the/monitored
if (( $? > 0 )) then
    echo "An error occurred with inotifywait" >> logfile
    exit 1
else
    echo "Received access event from inotifywait" >> logfile
    /sbin/poweroff &
fi
exit 0
should work.
 
1 members found this post helpful.
Old 10-04-2012, 12:01 PM   #7
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 34

Original Poster
Rep: Reputation: 16
@TobiSGD, where were you 5 years ago when I was originally looking for this solution? Thanks for the elegant solution!

EDIT: on Debian (and possibly others) this [is|may be] in the inotify-tools package.

Last edited by Hailey's_Comet; 10-04-2012 at 12:06 PM.
 
Old 10-04-2012, 12:41 PM   #8
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 34

Original Poster
Rep: Reputation: 16
To make it end-user configurable for multiple monitoring, I will be making a script that will be callable with args from init scripts, but for now this is what I am using (unconfigured state):
Code:
#!/bin/bash
monitor="/path/to/shared/dir"
logfile="/var/log/samba/smbshutdown.log"
success="Recieved shutdown command via samba"
failure="An error occurred with smbshutdown->inotifywait"
cmd="/sbin/poweroff &"

inotifywait -e access "$monitor"
if (( $? > 0 )) then
    _date=`date`
    echo "$failure @ $_date" >> "$logfile"
    exit 1
else
    _date=`date`
    echo "$success @ $_date" >> "$logfile"
    $cmd
fi
exit 0
When I am done, I will post it to bashscripts.org so I don't lose it!


.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UBUNTU: can I run startup script only (not on shutdown)? fopetesl Linux - Software 8 06-10-2010 04:16 AM
Getting an /etc/init.d script to run at system shutdown forrie Linux - Server 6 05-05-2010 02:19 PM
init script does not run at the shutdown time procfs Linux - Newbie 4 02-16-2010 03:00 AM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 02:34 PM
How to run a script at startup after a shutdown? kklein9 Linux - Software 3 01-27-2006 04:32 PM


All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration