I'm new to linux, trying to switch over from Windows, and I could really use some help. This is actually my first time using a forum such as this so please forgive any errors I make.
I'm using Linux Mint XFCE 64-bit and I have two scripts located in /usr/local/bin/custom, as can be seen as follows:
dasaint@X1:~$ which load-ssh-keys
/usr/local/bin/custom/load-ssh-keys
dasaint@X1:~$ which rescanscsi
/usr/local/bin/custom/rescanscsi
dasaint@X1:~$ whereis rescanscsi
rescanscsi: /usr/local/bin/custom/rescanscsi
dasaint@X1:~$ whereis load-ssh-keys
load-ssh-keys: /usr/local/bin/custom/load-ssh-keys
/usr/local/bin/custom
is in my global path, as has been set in /etc/environment
dasaint@X1:~$ echo $PATH
/home/dasaint/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin/custom:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Yet when I run rescanscsi
, I get the following error:
dasaint@X1:~$ sudo rescanscsi
sudo: rescanscsi: command not found
The strange thing is, if I run sudo /usr/local/bin/custom/rescanscsi
it works just fine.
And if I run the other script, load-ssh-keys
, without specifying the absolute path, it also works just fine. The contents of the scripts are:
#! /usr/bin/bash
#
# /usr/local/bin/custom/rescanscsi
#
# ReScan all SCSI/SATA Hosts
#
for SHOST in /sys/class/scsi_host/host*; do
echo -n "Scanning ${SHOST##*/}..."
echo "- - -" > ${SHOST}/scan
echo Done
done
and
#! /usr/bin/bash
#
# Script: load-ssh-keys.sh
# path: /usr/local/bin/scripts
# Purpose: add SSH private keys into ssh-agent
# Dependencies: '/usr/bin/expect'
# '/usr/bin/ssh-add'
#
# '/usr/bin' must be included in the system path
#
# SYNOPSIS
# --------
# Reads the passphrase from '~/keypsph' and stores it in the variable, 'PSPH', then
# calls '/usr/bin/expect' to spawn ssh-add to add the SSH private keys into
# ssh-agent and provide (send) the passphrase for the keys, followed by a <return>.
#
# '/usr/bin/expect' can be installed with:
# sudo apt install expect
#
# Guide: https://stackoverflow.com/questions/13033799/how-to-make-ssh-add-read-passphrase-from-a-file
#
# Initialize a variable to store an exit code of '0'
EXITCODE=0
#
# Check whether the passphrase file, 'keypsph' exists in the user's home directory.
# If not terminate the script with an appropriate message and error code.
if [ ! -f ~/.ssh/keypsph ]; then
echo -e "ERROR: Passphrase file not found in $HOME/.ssh\nExiting..."
exit 1
fi
# Read the passphrase from file, 'keypsph'
PSPH=$(cat ~/.ssh/keypsph)
#
# Call '/usr/bin/expect' to spawn ssh-add to add the SSH private keys to X2 into
# ssh-agent and provide (send) the passphrase for the keys, followed by a <return>.
expect << EOF
spawn ssh-add "$HOME/.ssh/x1-x2_key"
expect "Enter passphrase for /home/dasaint/.ssh/x1-x2_key:"
send "$PSPH\r"
expect eof
EOF
# Error Handling...
if [[ $EXITCODE != 0 ]]; then
echo -e "Error adding x1-x2_key to SSH Agent\nExiting..."
EXITCODE=$?
exit $EXIITCODE
fi
#
# Read the passphrase from file, 'keypsph'
PSPH=$(cat ~/.ssh/keypsph)
#
# Call '/usr/bin/expect' to spawn ssh-add to add the SSH private keys to X3 into
# ssh-agent and provide (send) the passphrase for the keys, followed by a <return>.
expect << EOF
spawn ssh-add "$HOME/.ssh/x1-x3_key"
expect "Enter passphrase for /home/dasaint/.ssh/x1-x3_key:"
send "$PSPH\r"
expect eof
EOF
# Error Handling...
if [[ $EXITCODE != 0 ]]; then
echo -e "Error adding x1-x2_key to SSH Agent\nExiting..."
EXITCODE=$?
exit $EXIITCODE
fi
#
# Read the passphrase from file, 'keypsph'
PSPH=$(cat ~/.ssh/keypsph)
#
# Call '/usr/bin/expect' to spawn ssh-add to add the SSH private keys to X4 into
# ssh-agent and provide (send) the passphrase for the keys, followed by a <return>.
expect << EOF
spawn ssh-add "$HOME/.ssh/x1-x4_key"
expect "Enter passphrase for /home/dasaint/.ssh/x1-x4_key:"
send "$PSPH\r"
expect eof
EOF
# Error Handling...
if [[ $EXITCODE != 0 ]]; then
echo -e "Error adding x1-x2_key to SSH Agent\nExiting..."
EXITCODE=$?
exit $EXIITCODE
fi
#
# Read the passphrase from file, 'keypsph'
PSPH=$(cat ~/.ssh/keypsph)
#
# Call '/usr/bin/expect' to spawn ssh-add to add the SSH private keys to X8 into
# ssh-agent and provide (send) the passphrase for the keys, followed by a <return>.
expect << EOF
spawn ssh-add "$HOME/.ssh/x1-x8_key"
expect "Enter passphrase for /home/dasaint/.ssh/x1-x8_key:"
send "$PSPH\r"
expect eof
EOF
# Error Handling...
if [[ $EXITCODE != 0 ]]; then
echo -e "Error adding x1-x2_key to SSH Agent\nExiting..."
EXITCODE=$?
exit $EXIITCODE
fi
#
# Exit the script with the appropriate exit code
exit $EXITCODE
I have searched the internet for answers but no one seems to have a comparable issue. I am at my wits end and I could really use some advice.
PS:
If I log in as root
using su -
and run rescanscsi
without the absolute path, it also runs just fine.
sudo
is invoking the copy of thessh-load-ssh-keys
command that's in/usr/local/bin/custom
and not a copy that's in another location? – Sotto Voce Apr 17 '23 at 04:23