Reputation: 101
I am running a sinatra web app that gets a file (upload) from the user. It then transfers the file to a server via scp. Can I grab the filename from the params Hash and set it as an environment variable and pass it to the scp command. Below is a snippet of my code.
ENV[file] = params['arne_site_file'][:filename]
transfer = `scp -i /opt/zabbix-proxy/etc/.ssh/id_rsa $file [email protected]:/home/zabbix/ARNE_5216_files`
Params Hash is -
{
"arne_site_file" => {
:filename => "ARNE_SITE__BB5216_L16B_936441_HWY_54_A.xml"
},
"submit" => "Validate File"
}
Upvotes: 1
Views: 3496
Reputation: 101
Found the solution. It turns out I was missing quotes. ENV['file'] = params['arne_site_file'][:filename]. This resolved the issue. Great to know that env variables can be set by Ruby for other bash scripts to access.
Upvotes: 3