Beiträge von Jan im Thema „Script um eine Datei via SSH hochzuladen“

    Soll automatisch das Homeverzeichnis des User, der sich verbindet genutzt werden und darin die Datei anlegen werden, kann man dieses Script nehmen. So muss nur der Dateiname angegeben werden, ohne den kompletten Pfad.

    Hier noch eine Version, bei der man den Dateinamen (inclusive des vollen Pfades z.b. /home/testuser/meinedatei.txt )

    angibt, und dann auch den Text in der Eingabe angibt.

    Mit Strg+D speichert und beendet man die Eingabe.


    #!/bin/bash

    # Get the IP address, username, ssh key path, and file name

    echo "Enter the IP address of your VPS:"

    read vps_ip

    echo "Enter the username:"

    read username

    echo "Enter the path to your ssh key:"

    read ssh_key

    echo "Enter the name of the file:"

    read file_name

    # Connect to the VPS using ssh and key-based authentication

    ssh -i .ssh/$ssh_key $username@$vps_ip << EOF

    # Run the curl command to install rclone

    curl https://rclone.org/install.sh | sudo bash

    # Create a file with the specified content

    cat > $file_name

    EOF

    # Input the file content after connecting to the VPS

    echo "Enter the content of the file, followed by [CTRL]+[D] to save and exit:"

    cat | ssh -i .ssh/$ssh_key $username@$vps_ip "cat >> $file_name"

    Das hier macht Chatgpt daraus.

    Es wird nach IP, Username und name des SSh-Keys gefragt. Wird kein Key sondern ein Passwort zur Identifikation benutzt einfach leer lassen

    #!/bin/bash

    # Get the IP address, username, and ssh key path

    echo "Enter the IP address of your VPS:"

    read vps_ip

    echo "Enter the username:"

    read username

    echo "Enter the path to your ssh key:"

    read ssh_key

    # Connect to the VPS using ssh and key-based authentication

    ssh -i .ssh/$ssh_key $username@$vps_ip << EOF

    # Run the curl command to install rclone

    curl https://rclone.org/install.sh | sudo bash

    # Create a file with the specified content

    echo "This is the content of the file" > test.txt

    EOF