Sponsored Content
Top Forums Shell Programming and Scripting Need solution for my bash script executed localy for ssh remote machine Post 303046006 by Azura1003 on Tuesday 21st of April 2020 01:26:01 PM
Old 04-21-2020
Need solution for my bash script executed localy for ssh remote machine [SOLVE]

Dear members,


I'm having some difficulties to find a solution to my problem. I have passed over 2 days in internet to find something, but nothing is working. Maybe it's simply not possible, but before giving up I would like to ask here. Thanks in advance,
The aim of this script is to ask to an admin on the local machine the IP address of the remote machine that will be configured, stock the IP in a variable and then automatically connect via ssh and execute the script that will change the hostname of the remote machine. I know that the way I m trying to do cannot work because the variable are not are not send over ssh.
Do you have idea about how I can do this ? I insist that I really want to do it in that way, because I know there is some more easier way to do but I want to solve it in the form for my own knowleadge purpose.


Sorry for my approxative english.





Code:
#!/bin/bash
# Script administration poste assosiation linux
# Définition du compte root à utiliser lors de la connexion SSH
root='administrateur'
# Début script
PS3='Bonjour que voulez vous faire ?: '
options=("Configurer un poste""Reinitialiser un poste""Quitter")
select opt in"${options[@]}"
do
    case $optin
"Configurer un poste")
echo"Veuillez entrer l'adresse Ip du poste nous allons configurer son hostname et créer un compte utilisateur"
            read ip
ssh$root@$ip 
#On stock le troisieme octet dans la variable ipoctet3
            ipoctet3=$(echo $ip | awk -F '.' '{print $3}')
            ipoctet4=$(echo $ip | awk -F '.' '{print $4}')
echo$ipoctet3
echo$ipoctet4
if [ $ipoctet3-eq100 ] ; then
echo"Réseau Baobab détecté configuration en cours..."
echo"Le nom hostname sera PCbao"$ipoctet4
sed-i'1i PCbao'$ipoctet4'/etc/hostname
              sed -i '1d' /etc/hostname
              cat /etc/hostname
             fi
            ;;
        "Reinitialiser un poste")
            echo "Veuillez entrer l'adresse Ip du poste à réintialiser"
            ;;
        "Quitter")
            break
            ;;
        *) echo "mauvais choix $REPLY";;
    esac
done


Last edited by Azura1003; 04-23-2020 at 10:50 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

executng program on remote machine using ssh

I am trying to search and remove files from a list of servers. I want to find every occurence of this file on each machine and then remove it. If I execute the find command on the remote machine I would like to be able to pipe the output to xargs and remove the file. Does anyone know hat would be... (1 Reply)
Discussion started by: sewood
1 Replies

2. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

3. Shell Programming and Scripting

Cannot create variables via ssh on remote machine

Hello to all Background info: Local machine : Linux, /bin/bash Remote machine (for the user used for ssh) : SunOs, /bin/ksh (so we have different OS, different Shells) My problem : From the local host i execute $ var=bla $ result=$(ssh -q user@remote-machine " > echo \"this is... (12 Replies)
Discussion started by: black_fender
12 Replies

4. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

5. Shell Programming and Scripting

bash script to execute a command remote servers using ssh

Hello, I am running into few issues, please suggest me what I am missing. I am running this script on a linux host. Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Shell Programming and Scripting

Mount fails (because remote machine is off) bash script stops

Hi, I'm trying to automate a couple of mounts. (I would do this in fstab, but the auto feature causes the virtual machine I'm running in to freeze when it boots up) If the machine I'm trying to connect to is OFF, I get the host unreachable error and then the bash script stops. The problem is... (3 Replies)
Discussion started by: jdilts
3 Replies

7. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

8. Linux

Executing a script in remote machine through ssh

How to execute a script in remote machine through ssh I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine. ssh -l username <remote machine> "commands to be exceuted as ; separted" but how to put the script in the place of... (5 Replies)
Discussion started by: sanvel
5 Replies

9. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

10. Shell Programming and Scripting

Ssh bash script exits without remote command completion

Hi, My goal is to connect from unix server A to windows server B and call a bat file on windows. I am able to succeed in remoting to windows and executing a command, the issue i am facing is the shell scrip is exiting without making sure of bat file success. Can you please help me in... (4 Replies)
Discussion started by: pxp018
4 Replies
All times are GMT -4. The time now is 06:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy