open ssh server files automatically with apple script - macos

Hello respected persons ,
i am trying to build a apple script which first open terminal login in ssh with details and after login it open a python script which is on ssh server automatically . i wanna do all of these tasks in a single apple script . i already tried to build automatic ssh login and i did . but i am facing problem how can i call a python script in ssh server automatically .
like i have a python file in ssh server /home/exe/ai.py
so i want each time i run that apple script it login in ssh and open ai.py automatically .
i am new in apple script please help :(
i am trying it fro 3 days but no luck please help me :(

You could use another do script:
do script ("python /home/exe/ai.py") in currentTab
Code:
tell application "Terminal"
set currentTab to do script ("ssh username#server.xxx;")
delay 5
do script ("python /home/exe/ai.py") in currentTab
end tell
Note: this doesn't check for errors or handle exceptions, so you'll want to consider implementing something like that in order to deal with it if that's a concern.

Related

Is there a way to get my laptop to beep from within a bash script running on a remote server via SSH?

I have a bash script that I have to regularly run on a remote server. Part of the script includes running a backup which takes a while, and after it has run, I have to hit "Y" to confirm that the backup worked before the script will continue.
I would like to know if there is a way to get my laptop to make a beep (or some sort of sound) when that happens. I know that echo -e '\a' makes a beep, but if I run it from within a script on the remote server, the beep happens on the remote server.
I have control of the script that is being run, so I could easily change it to do something special.
You could send the command through ssh back to your computer like:
ssh user#host "echo -e '\a'"
Just make sure you have ssh key authentication from your server to your computer so the command can run smoothly
In my case the offered solutions with echo didn't work. I'm using a macbook and connect to an ubuntu system. I keep the terminal open and I'd like to be informed when a long running bash script is ready.
What I did notice is that if I shutdown the remote system then it will beep the macbook and show an alarm icon on the relevant tab. So I have now implemented a bit of dirty workaround:
sudo shutdown 1440 && shutdown -c
This will initiate the system to shutdown and will immediately cancel the request. And I do get the alarm beep + icon. You will need to setup sudo to allow the user to permit shutdown. As it was my own remote server it was no problem but could limit the usability for others.

How to run screen using bash script

I am developing an application on Linux CentOS server. I need to automatically after registration of each use server create a screen to run some codes in loop for user.
When I use bash script to create new screen, it can't open screen and run commands in that screen.
For example, I want to open an screen and I run a php file in that screen. I have created a bash script test.sh but when I run this using cron tab it doesn't work.
screen
php php.php
Please tell what can I do to solve this?
It's quite easy to do this and such a thread already exists.
screen -d -m yourcommand

Opening an ssh connection and keeping it open on startup

I need to open an ssh connection on login and keep it open, but to not acutally do anything with it. It would be best if all of it would run in the background.
I created an automator application and made it run a shell script on the bash. The script looks as follows:
sshpass -p 123456 ssh 123456#123.123.123.123
If i try to run the application i keep getting an error message, however if i execute the exact same script in an terminal it works just fine.
Is there any way i can open that connection with an automator application and keep in the background?
You can send a KeepAlive packet to stop the pipe from closing.
In your ~/.ssh/config, and the following:
Host *
ServerAliveInterval 300
ServerAliveCountMax 2
What this says is that that every 300 seconds, send a null (keep-alive) packet and give up after 2 tries.
Source: http://patrickmylund.com/blog/how-to-keep-alive-ssh-sessions/
Do you really need to involve Automator at all?
Just save the script (say, foo.sh) in a folder with the same name as the script (i.e. foo.sh as well).
Put this folder in /System/Library/StartupItems/ and it will run when you start up your machine.

Running a script after user logs in

How could a script wait for the login process to complete before running a command in shell script in Mac OS X?
I have tried wait and sleep commands, but that doesn't seem to stop the script running under the root that owns the login process.
I want the script run after the user logs in.
There are 2 easy(ier) options:
Create a Login Item. To see an example, click here.
Use launchd. You don't have to install anything. All you need to do is to create a configuration file to tell launchd what to do, and save it (with proper permissions) on a specific directory that's read by launchd.

Shell script execution using action script 3.0

I have shell script command , i would like to execute it using action script 3.0.
Here is my shell script below
#!/bin/sh
set backslash_quote = "yes"
osascript -e "tell application \"System Events\" to set visible of some item of\
( get processes whose name = \"Terminal\" ) to false"
Where is the shell script that you are trying to execute? Is it on the server that the Flash will be hosted from or is it on the end users computer?
If it is on the server then you will need to set up a service to do this. Personally, I recommend PHP.
If it is on the end users machine, take a look at Creating Hidden File with Flex/AIR on Win. The answer in that link will give you an idea how to execute scripts on the users machine... Though I am pretty sure that will only work in AIR apps.

Resources