0

I have a iphone app that can remotely shutdown a mac computer. I would like this app to shutdown my Ubuntu computer.

I'm getting following messages from the application when trying to shutdown:

When Ubuntu is off:

"Connection error"

When Ubuntu is on:

"zsh:1: command not found: osascript"

This makes me think the app actually manage to access zsh. And if so: should I not be able to make an alias for "osascript" like this:

alias osascript="shutdown -h now"

Problem is I still get the message(in the Iphone app):

"zsh:1: command not found: osascript"

Any ideas why? My guess is that the app is using SSH and it is using same username as the alias in Ubuntu.

For failsearch: Am I supposed to see remote access command in ".zsh_history"? I cant see any command from the app here.

  • What is the name of that iphone app? How does it access your computer? If it uses ssh, did you need to provide a password? Did you see any login attempts at your ubuntu log files? – michas Jun 25 '16 at 21:53
  • App: tommasomadonia.com/wakeup/server . I am providing username/password for login. Cant find out where to find remote access log files – Grains Jun 26 '16 at 7:02
  • 2
    osascript is the command line AppleScript interpreter, looks like the iPhone app is using AppleScript to issue shutdown commands – forquare Jun 27 '16 at 10:38
  • I think it's very likely that your osascript alias isn't being loaded. Perhaps your zsh startup script thinks it's not running interactively and is skipping the alias definitions. – Edward Falk Jun 27 '16 at 19:04
1

Do not use apps that do not support Linux. "RMsrv Reboot" works great with starting and shutting off Linux.

0

The error message is at least consistent with a failed attempt to run a command directly through ssh, e.g. ssh someuser@somehost somecommand. Depending on how zsh is started and in which configuration file you put the alias by the app it is possible that it was just not loaded. Also, the history file will only be written by interactive sessions (which is a "Good Thing™": imagine if every zsh script would dump its content into your history file on execution).


osascript is the command line AppleScript interpreter (thanks to forquare for the hint). As such it is not available for Ubuntu. But it is likely that the app is running some small script via command line parameter to shut down the Mac.

  • If shutting down your machine is the only thing you want to do, you could just place some script in /usr/bin/osascript on your Ubuntu machine that shuts it down. For example:

    #!/bin/sh
    sudo /sbin/shutdown -h now
    

    This assumes password-less access to at least shutdown -h now. You can achieve that by adding the following line to your /etc/sudoers or a file that is included by it:

    YOURUSERNAME ALL = NOPASSWD: /sbin/shutdown -h now
    
  • If you want to react to different commands (shutdown, reboot, etc.), you can try to to retrieve the command line parameters which the app uses for them. For that first place the following script with the name osascript in /usr/bin (In theory any path listed in PATH should do. Unfortunately ssh often uses its own settings for PATH. See below.) on your Ubuntu machine:

    #!/bin/sh
    logfile='/path/to/logfile'
    echo "$@" >> "$logfile"
    echo '---->8----' >> "$logfile"
    

    Do not forget to make it executable (chmod 755 /usr/bin/osascript).

    Now you can run through the different options the app has to offer and check the output in the logfile each time (tail -F /path/to/logfile might help). Now you only need to find the differences in each output and write a script that reacts accordingly.


As mentioned above, ssh may use its own settings for PATH, which might be quite different from the settings you get in your terminal session (echo $PATH). Luckily you can easily retrieve the PATH used by ssh with

    ssh localhost 'echo $PATH'

If you see /usr/local/sbin or /usr/local/bin in there, I suggest placing the script there, but any listed directory should do.

  • Thanks! The zshenv file made things happen. I did put the alias into an restart_function() to ignore the paramters. But now the app says "Failed to set wall message, ignoring: Interactive authentication required". Can I somehow make a restart function that dose not require authentication? – Grains Jun 25 '16 at 21:57
  • You probably do not want to set up something that can be run remotely without authentication on your machine. The fact that you allow anybody on the net to crash your machine directly is only the first problem, if you manage to miss a very small security concern it might allow them to do anything! – MAP Jun 25 '16 at 23:56
  • Understand. But I am already using login information. But it seems like the command by itself requires authentication once again according to the message. Also I am only interessted to do this on the local network if that makes Amy difference. – Grains Jun 26 '16 at 6:49
  • You could try password-less sudo. It is possible to configure sudo to allow password-less access only to specific commands, if you want to usually be asked for a password. – Adaephon Jun 26 '16 at 14:35
  • osascript is the command line AppleScript interpreter, looks like the iPhone app is using AppleScript to issue shutdown commands, so it is unlikely that the commands will be similar to the regular shutdown command, is is also highly unlikely that you will be able to copy the binary across to Ubuntu. – forquare Jun 27 '16 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.