Questions tagged [sh]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

scp with variable driven server is not working

#!/bin/ksh/ SERVER_NAME=bcpstd.root.net FOLDER_ROOT_PATH=/data/feed/daily CURDATE=`date +"%Y%0m%0d"` scp gfstd@${SERVER_NAME}:${FOLDER_ROOT_PATH}/details_all_data_${CURDATE}.dat.gz /local/...
Pat's user avatar
  • 111
1 vote
2 answers
312 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=...
Andrew's user avatar
  • 11
0 votes
1 answer
319 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 ...
Radu M.'s user avatar
  • 139
0 votes
1 answer
274 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 ...
Alex's user avatar
  • 19
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 # ...
Omexlu's user avatar
  • 143
1 vote
1 answer
758 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 ...
rs232's user avatar
  • 105
0 votes
1 answer
141 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 ...
Kaf's user avatar
  • 179
0 votes
0 answers
52 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....
rs232's user avatar
  • 105
1 vote
2 answers
143 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 ${...
parg0's user avatar
  • 11
1 vote
1 answer
433 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/...
xendi's user avatar
  • 414
0 votes
1 answer
821 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 ...
Whimusical's user avatar
1 vote
0 answers
740 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 ...
Ted's user avatar
  • 11
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 ...
Vikram's user avatar
  • 167
1 vote
1 answer
836 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 ...
TSG's user avatar
  • 1,852
0 votes
0 answers
671 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 ...
syntencoist's user avatar
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 ...
gnsr's user avatar
  • 203
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 ...
cherouvim's user avatar
  • 824
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 "...
me24hour's user avatar
0 votes
1 answer
165 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 * * * * /...
Tamilvanan's user avatar
0 votes
1 answer
584 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: ...
Deepak's user avatar
  • 1
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 ...
aio's user avatar
  • 21
2 votes
1 answer
984 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.
GoodMirek's user avatar
  • 203
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/"* ]] ...
h2odev's user avatar
  • 133
2 votes
1 answer
8k 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 ...
James Gan's user avatar
  • 396
-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 ...
user2019182's user avatar
1 vote
0 answers
269 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 ...
Dan's user avatar
  • 11
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 (...
user1011471's user avatar
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/...
laughingbovine's user avatar
-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 -...
Jin Kwon's user avatar
  • 135
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 ...
pruthvi's user avatar
  • 171
-4 votes
1 answer
324 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 ...
arxoft's user avatar
  • 105
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 - # <-...
gextra's user avatar
  • 205
0 votes
2 answers
402 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 ...
Faron's user avatar
  • 107
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 ...
SSpoke's user avatar
  • 161
0 votes
1 answer
126 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/...
Caterpillar's user avatar
  • 1,142
3 votes
3 answers
343 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.
mdpc's user avatar
  • 11.9k
-1 votes
1 answer
281 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 ...
Marin Sagovac's user avatar
-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....
mike's user avatar
  • 1
1 vote
1 answer
427 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 ...
rjt's user avatar
  • 584
3 votes
2 answers
501 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 ...
inspectorG4dget's user avatar
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: ...
Vishruth's user avatar
  • 101
0 votes
1 answer
209 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 ...
williamsdb's user avatar
2 votes
2 answers
251 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 ...
Alexander's user avatar
  • 125
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 ...
MyTitle's user avatar
  • 571
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 ...
Ríomhaire's user avatar
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 >...
Utkonos's user avatar
  • 426
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 ...
j4x's user avatar
  • 105
3 votes
5 answers
7k 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 ...
Justin's user avatar
  • 5,438
1 vote
1 answer
229 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:...
Justin's user avatar
  • 5,438
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 ...
DarthCaniac's user avatar