Bunu deneyebilir ve çalışıp çalışmadığını görebilirsiniz. MacOS'ta çeşitli Linux (CentOS, Ubuntu, vb.) Sunucularına giden benim için iyi çalışıyor:
RECENT=$(ssh someone@example.com ls -lrt /remote/path/ | awk '/.ubx/ { f=$NF }; END { print f }');
scp someone@example.com:/remote/path/${RECENT} /local/path/${RECENT};
İlk satır, uzantısıyla birlikte en son dosyayı alır .ubxve onu $RECENTdeğişkene atar .
Bir sonraki satır sadece SCP komutunun kendisini çalıştırır. Her iki çizgiyi de bu şekilde birleştirerek onu “tek astar” haline getirebilirsiniz:
RECENT=$(ssh someone@example.com ls -lrt /remote/path/ | awk '/.ubx/ { f=$NF }; END { print f }'); scp someone@example.com:/remote/path/${RECENT} /local/path/${RECENT};
Ve elbette — sadece kullanıcı, ana bilgisayar adı için değişkenler ayarlayabilir /remote/path/ve /local/path/bunu tek bir komutla çalıştırmak için bir Bash komut dosyasına yerleştirebilirsiniz, get_latest_ubx.shböylece her seferinde böyle bir komutu yazmak zorunda kalmazsınız kullanman gerek.
#!/bin/bash
# Assign the variables.
USER='someone';
HOST='example.com';
LOCAL_PATH='/local/path/';
REMOTE_PATH='/remote/path/';
# Get the most recent `.ubx` file and assign it to `RECENT`.
RECENT=$(ssh ${USER}@${HOST} ls -lrt ${REMOTE_PATH} | awk '/.ubx/ { f=$NF }; END { print f }');
# Run the actual SCP command.
scp ${USER}@${HOST}:${REMOTE_PATH}${RECENT} ${LOCAL_PATH}${RECENT};