Sponsored Content
Operating Systems Solaris Run automated bash commands from sh login shell Post 303015967 by randman1 on Tuesday 17th of April 2018 09:18:28 AM
Old 04-17-2018
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.
Code:
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.
Code:
/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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

run commands before login

What would be the best way to setup for a Linux box to run a few commands before the user logs in? (1 Reply)
Discussion started by: woofie
1 Replies

2. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

3. Shell Programming and Scripting

shell script to run a few commands help!

Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u I need to write a shell script which will run the following commands pg_dump bank > backup(Enter) Wait for bash prompt to appear coz it indicates that the command is... (23 Replies)
Discussion started by: perk_bud
23 Replies

4. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

5. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

6. Shell Programming and Scripting

how to run non-standard commands in bash script?

Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you. I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by... (12 Replies)
Discussion started by: EinsteinMcfly
12 Replies

7. UNIX for Advanced & Expert Users

Different redirection behavior in BASH/Linux when run under cron vice login ???

run_xfs_fsr is a xfs filesystem maintenance script designed to run under cron. The system is a home theater personal computer running mythbuntu 10.10, and is accessed remotely for these tests. cron runs a script, (xfs_fsr.sh) at 02:30 that runs the subject script under BASH and sets the... (3 Replies)
Discussion started by: keepitsimpleeng
3 Replies

8. Shell Programming and Scripting

[bash] run a shell who runs commands

Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Discussion started by: jerold
4 Replies

9. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

10. Shell Programming and Scripting

Need to track what Commands run in a login session

Hi I need to track what commands run in login session in solaris whether it is root or any normal users in bash shell. My actual requirement is that when a user (nomal/root) login into the system, whatever commands he run, it should log into file on specified path . I don't require command... (4 Replies)
Discussion started by: hb00
4 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 08:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy