Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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@192.168.1.1:/etc/dnsmasq.conf

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -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@192.168.1.1:/etc/dnsmasq.conf"

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

share|improve this question

1 Answer 1

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

 
discard

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.