Run automated bash commands from sh login shell

I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the designated user's login shell is sh. I would like to use the same commands and be able to use array variables which apparently are not supported by sh. The commands are saved in a local text file and the file name is used in plink's -m option. Each command is then executed via SSH. An example of some of the file contents are below.

cd /opt/audit
tsmin=`perl -MTime::Local -le 'print timelocal(0,0,0,7,10,2017)'`
tsmax=`perl -MTime::Local -le 'print timelocal(59,59,23,7,10,2017)'`
echo "R,$tsmin,$tsmax"
filelist=`ls FaultEvent_* | nawk -F'_' '$2$3>=2017110700 && $2$3<=2017110723 {print $0}'`
nawk -F',' -v tsmin=$tsmin -v tsmax=$tsmax '$1=="A" && $2>=tsmin && $2<=tsmax {OFS=",";$3=strftime("%F %T",$2);print $0}' $filelist /dev/null | sed 's/ *, */,/g'
nawk -F',' '$9 ~ "component" {OFS=",";print "S," $0}' ObjState_20171107 /dev/null | sed 's/ *, */,/g'
filelist=`ls DomainEvent_* | nawk -F'_' '$2$3>=2017110700 && $2$3<=2017110723 {print $0}'`
nawk -F',' '$12 ~ "component" {OFS=",";$3=strftime("%F %T",$2);print $0}' $filelist /dev/null | sed 's/ *, */,/g'

I cannot figure out how to format these commands to run under a bash subshell and return stdout. I thought the following would do it but I get "undefined variable" messages and no return. I also tried other variations with similar results.

/bin/bash << eof
cd /opt/audit
tsmin=`perl -MTime::Local -le 'print timelocal(0,0,0,7,10,2017)'`
...
echo "R,$tsmin,$tsmax"
...
eof

How can I run a series of commands in a bash shell from sh login shell and return stdout. Extra credit: I also need an alternative to strftime in the nawk statements since these Solaris 10 boxes do not have this function.

strftime is GNU awk ( gawk ) extension. nawk on Solaris isn't not gawk.

I don't think plink.exe will harm anything.
Did you execute either script in an interactive session? What be the results, errors? I don't see an immediate reason (besides what vgersh99 said) that script(s) should not run in both bash and sh , as there's nothing shell dependent in them, but I may overlook sonething as the script is complex and difficult to read, esp. without sample data.

Why do you use those perl scripts? Why that many (n) awk scripts? With some insight, people in here might propose a single awk script to you. Post sample data, directory structures, and desired results.

The remote servers have thousands of CSV files organized into 3 groups. The user supplies a start and end date and the script returns the records between the supplied dates/times. The script must first determine which files should contain the correct data (determined by file name = $filelist) then determine which lines from those files are between the start and end date (determined by unix timestamp field). The perl functions are to convert the user-supplied start and end date/time to epoch timestamp so time is relative to the server, not the user. This enabled me to skip time zone and DST implementation in the GUI since users can be in different time zones.

I did run the commands from an interactive session, which is a convenient way to test since it mimics what plink is doing. This is where I was seeing the undefined variable messages. When i included a pwd command, I found that the cd command was not executed either.

Since the initial post though, I learned that quoting the heredoc delimiter works. All the commands appeared to have run in bash and provided an output.

/bin/bash << "eof"
...
"eof"

I'm still not sure why this works but glad it does. I'm still faced with the timestamp conversion issue though. I played around with similar perl commands inside the nawk statement but am not having much luck. This issue doesn't have as big of an impact as did running the commands in bash instead of sh but it would be nice to resolve it.

---------- Post updated at 12:15 PM ---------- Previous update was at 11:57 AM ----------

Edit: I just realized that the login shell for these Solaris 10 boxes is csh rather than sh. Not sure is that changes things much

Oh yes, it does, be reassured! You may want to change shell to bash .

Is the problem solved now? If not, post data!

Yes, the problem pertaining to the title of this thread has been solved. I will start a new thread relating to the time conversion issue.

Thank you both for the help