0

I was running a script normally. But suddenly, all the commands in the same line with sshpass started being not recognized. For instance:

sshpass -p "$password" rsync -a -e "ssh -o StrictHostKeyChecking=no -p $port" "$username@$hostname:${src_dir}${dir}/" "${dest_dir}${dir}/"
dirs=$(sshpass -p "$password" ssh -o StrictHostKeyChecking=no -p "$port" "$username@$hostname" "ls -lt --time-style=long-iso '$src_dir' | grep '^d' | head -n 3 | awk '{print $8}'")

These commands run (head,ls and the rest) successfully in other parts of the script. sshpass is installed:

atmos_username@atmosserver:~$ which sshpass
/usr/bin/sshpass
bash: grep: command not found bash: head: command not found bash: awk: command not found bash: ls: command not found rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: error in rsync protocol data stream (code 12) at io.c(231) [Receiver=3.2.7] Copying /mnt/ops/lap_ops/data/KASTOM_OUT/Tiff_files/20240529 to /home/sftp/life-sirius/uploads/Tiff_files/ bash: rsync: command not found

My OS is:

atmos_username@atmosserver:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy

Output of declare -p PROMPT_COMMAND:

atmos_username@atmosserver:~$ declare -p PROMPT_COMMAND
-bash: declare: PROMPT_COMMAND: not found
atmos_username@atmosserver:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Output:

atmos_username@atmosserver:~$ . "/home/atmos_username/2024/ditsiaou_life-sirius/ubuntu_forum.sh"
Attempting SSH connection...
SSH Connection successful.
-bash: /mnt/ops/lap_ops/data/KASTOM_OUT/Tiff_files/: No such file or directory
trial=
bash: head: command not found
bash: awk: command not found
bash: grep: command not found
bash: ls: command not found
dirs= $(dirs)
Copy operation completed.
Delete of 3 days old
Directory /home/sftp/life-sirius/uploads/Tiff_files/20240528/ does not exist.
End of file
20240529  20240530  20240531
14
  • 2
    You already posted your question here - please decide which site you want to ask on and delete the other Commented May 31 at 11:21
  • Since I have to choose a site, which one do you think is more appropriate? I think Unix and Linux. Thanks. Commented May 31 at 11:23
  • I suspect you accidentally set PROMPT_COMMAND to a malformed command that tries to execute bash, head, awk etc in ~/.bashrc or somewhere else, what's the output of declare -p PROMPT_COMMAND?
    – kos
    Commented May 31 at 11:41
  • @kos atmos_username@atmosserver:~$ declare -p PROMPT_COMMAND -bash: declare: PROMPT_COMMAND: not found Commented May 31 at 11:45
  • 1
    So far as I can see, the whole pipeline is being passed to the remote host - so you will need to look at the $username user's login bash shell on $hostname - most likely the PATH environment variable is set incorrectly Commented May 31 at 12:17

1 Answer 1

0

The problem was in the remote pc. In the bashrc file of the remote pc :

echo 'export PATH=/mnt/lap_c/home/ditsiaou/2023/.../...//sshpass/bin:/mnt/lap_c/home/ditsiaou/2023/.../.../' >> ~/.bashrc

source ~/.bashrc

echo 'export PATH=/mnt/lap_c/home/ditsiaou/2023/.../...//sshpass/bin:/home/d/ditsiaou' >> ~/.bashrc

source ~/.bashrc

Thanks for the help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .