Saltstack commands inside bash scripts don’t work

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Saltstack commands inside bash scripts don’t work
# 1  
Saltstack commands inside bash scripts don’t work

In a Redhat Linux environment, I could run salt commands on the $ prompt but not inside my bash scripts.

It will say command not found and the $PATH variable is exactly the same outside and inside the script.


echo “running”
salt "*" ‘ls’

salt: command not found

$whereis salt or $which salt returns nothing. For any other commands it will show the exact path/filename. I tried under different shells ie /bin/sh and it’s the same result ie salt command not found.

Last edited by vbe; 3 Weeks Ago at 10:00 AM.. Reason: code tags please
# 2  
Welcome on board, don't forget to use code tags for your code and data...
When you say
$whereis salt or $which salt returns nothing.
your mean terminal/interactive mode?

And, hmm if your path is correct to your bash then

should be
#! /usr/bin/bash

# 3  
That is a typo in this forum. It’s (correct) like the below and the salt command doesn’t run but the echo “running” is working fine. I’ve tried with #!/bin/sh also. The same salt command works fine on the (interactive) shell (command line).

echo “running”
salt "*" ‘ls’

I cannot find anyone who has used the salt commands inside a shell script. If you do find any, please post it here. Appreciate it.

Last edited by vbe; 3 Weeks Ago at 11:32 AM.. Reason: code tags please
# 4  
In other words when you type which salt at your prompt it should return you the path... what is it?

Then if salt works in interactive at your prompt, and you see no path, it might be salt as a command does not exist, which means you have an alias somewhere in your environment...
When you type alias do you see alias salt=' ... somewhere?

Last edited by vbe; 3 Weeks Ago at 11:47 AM.. Reason: typos
This User Gave Thanks to vbe For This Post:
# 5  
$ which salt or $ whereis salt returns “no salt in /usr/.....”

The salt command path is NOT shown (unlike most Unix commands) but you can run salt from the Unix shell. Checked in alias also but found nothing.

Tried running the script with sudo -i and the same results.
# 6  
stack@undercloud (stackrc) ~]$ grep gurdev /etc/passwd
[stack@undercloud (stackrc) ~]$
[stack@undercloud (stackrc) ~]$ echo $PATH
[stack@undercloud (stackrc) ~]$ ./
./ line 5: salt: command not found
[stack@undercloud (stackrc) ~]$
[stack@undercloud (stackrc) ~]$ cat
echo "running"
echo $PATH
salt '*Compute-1' 'sudo virsh list'
[stack@undercloud (stackrc) ~]$
[stack@undercloud (stackrc) ~]$ which salt
/usr/bin/which: no salt in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/stack/.local/bin:/home/stack/bin)
[stack@undercloud (stackrc) ~]$ whereis salt
salt:[stack@undercloud (stackrc) ~]$
[stack@undercloud (stackrc) ~]$
[stack@undercloud (stackrc) ~]$ salt '*Compute-1' 'sudo virsh list'
     Id    Name                           State
     1     instance-000003a6              running
     3     instance-00000afe              running
     4     instance-0000172d              running
     7     instance-00001472              running
     8     instance-000016b2              running
     10    instance-000003a0              running
[stack@undercloud (stackrc) ~]$

# 7  
Can you post output of :
find $HOME -type f -name 'salt' 
ls -dl $HOME/salt

From the whereis output salt is located under /home/stack

This looks like openstack software, which on the undercould home stack user has a environment file stackrc.
Source that file if it exist in your script.


Last edited by Peasant; 2 Weeks Ago at 01:05 AM.. Reason: Added additional info..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #100
Difficulty: Easy
Unix has built-in networking functions so that computers can easily exchange computer data.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Work with file inside zip

Hi all, I`m trying to find 3 files from all zip files in a directory (and its all its subdirectories) recursively, and concatenate them correspondingly along with the filename (possibly path of that file from current directory). Suppose I have 3 zips ... (2 Replies)
Discussion started by: senhia83
2 Replies

2. Shell Programming and Scripting

Why commands inside bash script lost effectiveness?

Hi, I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment. For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel"... (4 Replies)
Discussion started by: hce
4 Replies

3. Shell Programming and Scripting

Why doesnt if inside a while loop work ?

I am looping through a file in bash and performing some operations on it. Here is the code. cat test.dat - One Two Three Case 1: With if inside while loop Output: One file found :) ------------------ isn't it supposed to print following output !!! one (3 Replies)
Discussion started by: qwarentine
3 Replies

4. Shell Programming and Scripting

Bash scripts as commands

Hello, the bulk of my work is run by scripts. An example is as such: #!/bin/bash awk '{print first line}' > Intermediate.ter awk '{print second line}' > Intermediate_2.ter command Intermediate.ter Intermediate_2.ter > Output.out It works the way I want it to, but it's not... (1 Reply)
Discussion started by: Leo_Boon
1 Replies

5. Shell Programming and Scripting

$RANDOM does not work inside a shell script

Hi folks I'm coding on Ubuntu 9.04 standard shell. I'm writing a script that needs to generate a random number at some point of its execution. When I do echo $RANDOMas a command inside shell, I clearly get some randomly generated number However when I do i=`$RANDOM` echo $ior even... (14 Replies)
Discussion started by: ksk
14 Replies

6. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./ I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

9. UNIX for Dummies Questions & Answers

Why do basic unix commands not work in BASH

Why do basic unix commands such as "ls" not work in "BASH" mode?? I am frustrated!! (10 Replies)
Discussion started by: PixelLover
10 Replies

10. Shell Programming and Scripting

scripts cant work correct

Hi all, Can any one help me to look on script below. My script can work correctly. For the if compare if more than 500 will go to -stop but it go to echo $?. what happen to the $? , cant use to compare as integer??? Any one please help,urgent...thanks! #!/bin/ksh sqlplus -s... (11 Replies)
Discussion started by: jaseloh
11 Replies

Featured Tech Videos