Questions tagged [sh]
The sh tag has no usage guidance.
65
questions
1
vote
2
answers
151
views
Linux: Run a specific command as another user?
I want to be able to allow users to run a specific command as another user, is this possible?
I have a script that reads a remote file through ssh to get a status, something like:
#!/usr/bin/sh
state=...
0
votes
0
answers
24
views
Shebang = how to verify source/target file mounted via --bind
On a router (busybox) I'm limited to shebang. On devices like these relaying on squashfs and flash storage it's common practice to mount --bind files from USB/CIFS/JFFS onto a file provided by the ...
0
votes
1
answer
241
views
Run sh script as root on Ubuntu every time a user logs-in
I want to run a sh script as root on Ubuntu automatically, every time a user logs in. I tried to place the script in /etc/profile.d The script is being run but is run using the account of the user not ...
0
votes
1
answer
244
views
When I run `sudo passwd` I set my password and the script exits okay. Running `sudo chsh -s /bin/bash` immediately after fails
Long time lurker, first time poster.
My linux server is behaving strangely. When I run sudo passwd, I can set my password up correctly. However, if I run sudo chsh -s /bin/bash, the command returns ...
1
vote
2
answers
7k
views
8: Syntax error: word unexpected (expecting ")")
The following code:
weekday=$(date +%a)
day=$(date +%d)
month=$(date +%m)
if [[ ( $month == 03 || $month == 10 ) && $weekday = "Sun" && $day > 24 ]]
then
# ...
1
vote
1
answer
652
views
mask public IP addresses from any command output (for diagnostic)
I'm writing a script to extract information from BusyBox v1.25.1/Linux 2.6.36/router where the user can simply run the script and copy/paste the output into a submission form to request support. The ...
0
votes
1
answer
118
views
How to run a shscript on reboot
I am trying to run a script on reboot that enables a port forward to a remote server. I made i script that it works if i run it in terminal. But i am not able to run it on crontab reboot:
@reboot ...
0
votes
0
answers
51
views
executing part of script coming from external file
I have some information stored in an external file.
On the main script I'm parsing the secondary file to work out how information should be processed.
To do so I have tried this:
cat ./secondary....
1
vote
2
answers
141
views
Compromised CentOS 6.10 server
I am working on a compromised server. CentOS 6.10 with [kthreadd] taking up most of the CPU.
Old crontab deleted, and the following content put in place:
*/4 * * * * R=$(shuf -i 1-29 -n 1);sleep ${...
1
vote
1
answer
415
views
Shell script prevent switching to other shell or escape from it
If in my automation script, I need to do something like install oh-my-zsh, I will have a .sh script like this:
#!/bin/sh
runuser -l user -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/...
0
votes
1
answer
740
views
Bash command to execute a foreground set of background commands
I got 2 commands that run blocking the input in the console, so they must be ended with CTRL+C. I don't like running them in background, since I lost control for interruption. But otherwise I cannot ...
1
vote
0
answers
677
views
Why are psql commands in my script suddenly being killed by jenkins / hudson?
I have an existing jenkins job that kicks off a shell script to copy my prod environment into qa.
We added a lot of data to prod (gzip dump went from 2gig to 15gig) and all of the sudden my jenkins ...
0
votes
1
answer
3k
views
commands not running from crontab [duplicate]
I have setup and cron to check if a port is busy or free and if its free then it sends and email and then start golang api service
send mail is working properly but api server is not getting started
...
1
vote
1
answer
785
views
Set alias from sh script in ESXi 6
I have created a simple script to setup an alias on an ESXi 6.7 host:
#!/bin/sh
alias ll="ls -la"
echo "Profile done"
When I run the script I see the echo'd message on screen, but the alias is not ...
0
votes
0
answers
661
views
linux sh -c replace echo not working
This seems like it should have a super simple answer, but I have search for a while and tried different suggestions to no avail.
As an example, I am trying to create a function that will be available ...
10
votes
4
answers
27k
views
Shell script from local machine to execute command in remote machine, then continue on the local machine
The problem is this: I want to copy files from a remote machine.
I am looking for a way to write a shell script that would connect to the remote machine, get the location of the stored file, once I ...
38
votes
3
answers
7k
views
#!/bin/sh vs #!/bin/bash for maximum portability
I usually work with Ubuntu LTS servers which from what I understand symlink /bin/sh to /bin/dash. A lot of other distros though symlink /bin/sh to /bin/bash.
From that I understand that if a script ...
1
vote
1
answer
2k
views
How to escape double quotes and exclamation mark in password?
I have the following code:
curl -s --insecure -H "Content-Type: application/json" -X POST -d "{\"username\":\"$1\",\"password\":\"$2\"}" http://apiurl
In the above curl command I want to escape the "...
0
votes
1
answer
158
views
Multiple crons at same interval fails - linux crontab
In my server, I have scheduled following set of cron files.
00 21 * * * /bin/sh /path/db_backup.sh
*/2 * * * * /usr/bin/php /path/file1.php
*/2 * * * * /usr/bin/php /path/file2.php
...
*/2 * * * * /...
0
votes
1
answer
569
views
How to switch user in a shell command
I am creating a shell script to automate our certificate import process.
It will be running as root to update group policy.
Once complete, how can we change the root to logged in username in MAC?
Ex:
...
1
vote
4
answers
9k
views
After launching .sh script appearing 'must be connected to a terminal'
i have a short bash script which can run a file.
When im trying to start this by "x.sh start", there is appearing a warning 'must be connected to a terminal'. How to start this? I tried some configs ...
2
votes
1
answer
853
views
In bash script, what is difference between > and >| redirections?
What is the difference between the following two redirection commands?
ls > out
ls >| out
They both seem to produce the same output.
3
votes
1
answer
12k
views
Linux shell script "No such file or directory"
I have created a shell script to complete 3 simple tasks (zip a directory, rename the final file and delete the source directory). The script source is below:
#!/bin/bash
if [[ $2 == *"/data/"* ]]
...
2
votes
1
answer
7k
views
What's the accurate meaning of "exec &>/var/log/a.log" in a shell script?
I think this is some kind of io redirect but it looks different to the examples from manual. Normally, we can redirect stdout of the script by following line:
exec 1> /var/log/a.log
But I saw ...
-1
votes
2
answers
3k
views
Downloading .sh file from git repository [closed]
I am trying to download a file from my git repository onto a VM, and I do so running the following command:
curl -O "https://git.com/projects/RENG/repos/test.sh" -k
After I run this command I see ...
1
vote
0
answers
262
views
Hundreds of zombie sh processes spawn then die
I have a few Ubuntu Server 14.04.03 LTS boxes that will occasionally spawn hundreds of zombie sh processes. This process spike will be picked up by the monitoring system, and send an alert. I found ...
2
votes
1
answer
3k
views
How to watch for arrivng files if inotifywait unavailable? [closed]
I have a directory that gets written to when other machines send files via FTP. I want to put something in place that notices when files arrive and if their file name contains a particular substring (...
2
votes
0
answers
2k
views
Init script has permissions issues, but running with /bin/sh resolves them? [closed]
Can someone tell me what's going on here? As far as I knew, these ways of executing an init script are identical.
box:~# whoami
root
box:~# /etc/init.d/nginx restart
nginx: [emerg] open() "/var/run/...
-2
votes
1
answer
1k
views
How can I execute sibling scripts outside the directory? [closed]
$ ls -l
bin/
$ ls bin/
startup.sh shutdown.sh
I wrote a script named restart.sh inside the bin/ looks like
#!/bin/sh
sh ./shutdown.sh
sh ./startup.sh
Now the bin/ directory looks like this.
$ ls -...
1
vote
2
answers
3k
views
script to count the occurence of the particular string in the given time interval
We are trying to write a script "sendemail.sh" to count the number of occurrence of a particular string in a log file "SendEmail.log" within the given interval.
We have a log file. In that we are ...
-4
votes
1
answer
323
views
Killing a bash sh script [closed]
I made an .sh file load.sh which has (almost) unlimited loop of curl requests. I run this as $ bash load.sh. Now it just keeps running the loop. I can't cancel its execution. It keeps running. I ...
0
votes
2
answers
2k
views
running a remote shell script that switches to a user does not return to the issuing local server shell
When I run a script such as this:
ssh -t [email protected] '/tmp/somescript.sh'
where the script is defined as:
#!/bin/sh
mkdir -p /data/workday/cred
chown -R myuser:myuser /data
su myuser - # <-...
0
votes
2
answers
383
views
Why does system lag or stall after successful completion of tar backup command?
I have a script that runs backup of system files via tar as a cronjob for my server. Every time the script is being fired off, it completed the task as successful. All backups were tested and appeared ...
0
votes
1
answer
3k
views
sh bash script ambiguous redirect pid of file using single quotes
I have the following new line in my .sh file
su --session-command='$javaCommandLine & >>$serviceLogFile 2>&1 & echo \$! >$pidFile' $serviceUser || return 1
When I had it with ...
0
votes
1
answer
123
views
rkhunter warning message /bin/sh
I'm running Ubuntu 10.04.4 LTS with fully update OS. The below messages is from rkhunter, What does it mean? Can anyone please explain.
Warning: The file properties have changed:
File: /bin/...
3
votes
3
answers
312
views
How can a sh script determine if it was started as a cron job as opposed to interactive or background?
I'd like to use the same scripting for cron and interactive, just wondering if there was a universal way over UNIX/Linux systems to easily make this determination.
-1
votes
1
answer
263
views
Host command reverse result [closed]
For example I do in Linux using host command:
host yy.yyy.yy.y
Result:
Host z.zzz.zz.z.in-addr.arpa. not found: 3(NXDOMAIN)
Then I repeat host command in a reverse with z.zzz.zz.z than I got a ...
-1
votes
2
answers
1k
views
run ntpdate from rc.local [closed]
My /etc/rc.local is:
#!/bin/sh
touch /var/lock/subsys/local
/data/automatic/ntpdate.sh
My /data/automatic/ntpdate.sh is:
#!/bin/sh
echo "RWQERWER" >> /data/logs/1.log
ntpdate ntp.fudan.edu....
1
vote
1
answer
421
views
Multiple spaces in folders and files for rsync backup via /bin/bash /bin/sh
Need a one-time backup of two old messy Windows XP machines because of a company split. Using CentOS 6 x64 minimal install, i mounted some MS Windows NTFS harddrives installed locally via ntfs3g and ...
3
votes
2
answers
482
views
`sh` access denied over ssh connection
I have an ubuntu server and a windows XP client running Cygwin. The server ssh's into the client and tries to execute a shell script with some params, with the following command:
ssh user@IP_ADDR 'sh ...
0
votes
1
answer
57
views
update all the servers through one virtual servers using Storage are network virtual machine
Using UBUNTU and Virtal Box by Oracle,
and Using this script to start nginx in Virtual Box, and placing it in Virtual box inside~/init.d
#!/bin/bash
### BEGIN INIT INFO
# Provides: ...
0
votes
1
answer
205
views
date and other commands no longer working in sh script
I have a shell script that used to run find on Ubuntu 10.04 but since I have moved to 12.04 it doesn't work as before throwing the following messages:
/home/checks.sh: 1: /home/checks.sh: date
: not ...
2
votes
2
answers
248
views
how to remove ^m symbol
I need to compile Qt under Debian 64-bit. I downloaded sources but there is ^M symbol everywhere in every file in the end of lines and bash doesnt run configure script. How to remove it from all files ...
1
vote
1
answer
2k
views
Run .sh (no service) file on startup
How to execute a script once at startup time on CentOS 6.3? I added file with following containment
#chkconfig: 2345 95 20
#description: Some description
sh /opt/somePath/my.sh
into /etc/ini.d and ...
0
votes
4
answers
2k
views
Assigning environment variables for CRON
I have a .sh script that creates a .tar.gz file and transfer's it to a remote server using RSA keys for authentication.
The script will run from terminal but it will not when I try to set it up as a ...
7
votes
2
answers
4k
views
How do I enable XRandR in Xvfb or disable it in firefox when running firefox headless?
I am trying to start firefox headless. The following is the beginning of the shell script that starts it:
#!/bin/sh
Xvfb :99 >/dev/null 2>&1 &
XVFB=$!
sleep 3
firefox --display=:99 >...
3
votes
3
answers
1k
views
SH conditional redirection [closed]
I want to be able to redirect some output of my script to /dev/null based on a command line switch.
I don't know how should I do it.
In a silly way, it would be something like this (in a too ...
3
votes
5
answers
6k
views
How to execute shell scrips without creating files
How is it possible to execute a shell script without creating a file? For example assume I have the following script (testscript):
#!/bin/bash
function run_free() {
free -m
}
run_free
I then of ...
1
vote
1
answer
223
views
Does the sh command use the users shell
Does the sh linux command use the users current shell, even if its not bash? For example, let's say the user bob is running csh. If I create a script with functions and csh and try and execute it with:...
1
vote
2
answers
1k
views
PHP, SSH2, and Bash Scripts not getting along
I am using the SSH2 library in my PHP to execute a SH script on a remote server. When I run it manually on SSH, it works just fine. However, when I try to run it through PHP, the script starts, but ...