Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a TCL expect script that runs a scp command for uploading a config file to my DNS server:

#!/usr/bin/expect -f

set config "~/dnsmasq.conf"

spawn /usr/bin/scp "$config" root@

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
    -re ".*password.*" {
        exp_send "$password\r"
        expect {
            -re ".*denied.*" {
                exit 7

I would like to return a specific error code if the scp utility can not be found. Currently the script exits with a status of 1. If the script exits with a status of 7, I can handle that because I know it's an access denied error. The error that shows up in the Apache log is:

couldn't execute "/usr/bin/scp": no such file or directory
    while executing
"spawn /usr/bin/scp "$config" root@"

How can I return an error code of 5 or something at this point?

share|improve this question
up vote 3 down vote accepted

Best way to do it would be to check if it exists and is executable:

if { ! ([file exists /usr/bin/scp] && [file executable /usr/bin/scp])} {
    puts stderr "/usr/bin/scp does not exist or is not executable"
    exit 7

spawn /usr/bin/scp ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.