Change directory and execute lua file in one command in Putty

Thread Starter

justinvil1103

Joined Apr 6, 2016
41
Hi All,


I am trying to read temperature for a device using putty. I trying to run a Lua file in putty in one line of command.

Exp: File to run : heater_monitor.lua, Path: media/umass-32/heater_monitor.lua

Can I run the following file (heater_monitor.lua) as follows in the path?:

cd /media/umass-32 && heater_monitor.lua

Which will run the Lua script from the subfolder (/umass-32)

Thanks,
WJ
 

Attachments

djsfantasi

Joined Apr 11, 2010
9,163
Your two path specifications for the lua file are not the same. So the answer depends on the FULL path specification of the lua file and the working directory defined for Putty.

I need more information to answer your question. Start by specifying the full path specification and the full working directory for putTy.
 

Thread Starter

justinvil1103

Joined Apr 6, 2016
41
Your two path specifications for the lua file are not the same. So the answer depends on the FULL path specification of the lua file and the working directory defined for Putty.

I need more information to answer your question. Start by specifying the full path specification and the full working directory for putTy.
The full path is "/media/umass-sim-32/

the lua file is in the "umass-sim-32" folder see attached picture
 

Attachments

djsfantasi

Joined Apr 11, 2010
9,163
Then there must be a folder in the root directory of the drive labeled “media”. I.e., “C:/media”. Try putting a period before the initial slash if the media folder is in the execution directory instead.
 

Ya’akov

Joined Jan 27, 2019
9,170
Hi All,


I am trying to read temperature for a device using putty. I trying to run a Lua file in putty in one line of command.

Exp: File to run : heater_monitor.lua, Path: media/umass-32/heater_monitor.lua

Can I run the following file (heater_monitor.lua) as follows in the path?:

cd /media/umass-32 && heater_monitor.lua

Which will run the Lua script from the subfolder (/umass-32)

Thanks,
WJ
As you have it in cd /media/umass-32 && heater_monitor.lua the shell will change directories to /media/umass-32 and then, if and only if the cd was successful, attempt to execute heater_monitor.lua.

This will only do what you want if heater_monitor.lua has UFS execute permissions (i.e.: at least chmod 550 if you are the owner of, or in the group of the file; and 555 if you are neither (world).

AND if /media/umass-32 is listed in $PATH (very unlikely). The fix is to use ./heater_monitor.lua or /media/umass-32/heater_monitor.lua where the first version uses the ./ to specify the cwd (current working directory), and the absolute path doesn't care where you happen to be in the filesystem.

Just a note, if heater_monitor.lua doesn't need to run with /media/umass-32/ then you can omit the cd and simply use the absolute path. The trick here is that executables won't run if they aren't in $PATH or have an absolute path on the command line. (./ is expanded before the shell executes, so becomes the same as writing the whole thing out).
 

Thread Starter

justinvil1103

Joined Apr 6, 2016
41
As you have it in cd /media/umass-32 && heater_monitor.lua the shell will change directories to /media/umass-32 and then, if and only if the cd was successful, attempt to execute heater_monitor.lua.

This will only do what you want if heater_monitor.lua has UFS execute permissions (i.e.: at least chmod 550 if you are the owner of, or in the group of the file; and 555 if you are neither (world).

AND if /media/umass-32 is listed in $PATH (very unlikely). The fix is to use /heater_monitor.lua or /media/umass-32/heater_monitor.lua where the first version uses the ./ to specify the cwd (current working directory), and the absolute path doesn't care where you happen to be in the filesystem.

Just a note, if heater_monitor.lua doesn't need to run with /media/umass-32/ then you can omit the cd and simply use the absolute path. The trick here is that executables won't run if they aren't in $PATH or have an absolute path on the command line. (./ is expanded before the shell executes, so becomes the same as writing the whole thing out).
Thank you, Max
 
Top