Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

learn more… | top users | synonyms (1)

0
votes
0answers
3 views

bash: Assigning the first line of a variable to a variable [migrated]

I have a multiline variable, and I only want the first line in that variable. The following script demonstrates the issue: #!/bin/bash STRINGTEST="Onlygetthefirstline butnotthesecond orthethird" ...
-2
votes
0answers
20 views

Free Nas Cron Job not finishing

I have a simple backup archival bash script that runs every night. I have 8-10 directories for our database servers with dump files of all the databases. The script in question is supposed to loop ...
1
vote
0answers
28 views

socat TCP file server

I'm trying to set up a simple socat fileserver using TCP to send small files (~100KB). Here are the one-line servers and client for one file: Server: socat -u -d -d OPEN:file.dat ...
-1
votes
2answers
41 views

how to extract mysql version by bash script in centos 6

I need to extract the mysql version in a bash script on CentOS 6 for a minimum requirements check Example: # mysql -V mysql Ver 14.14 Distrib 5.5.43, for Linux (x86_64) using readline 5.1 # mysql ...
0
votes
0answers
25 views

Shell Scripting - return to previous loop until process is completed then die/done [migrated]

I am writing a bash/shell script to automate some file filtering functions. I am stuck due to being new to scripting and I am not sure how to code the function in it to keep looping the top section of ...
0
votes
3answers
33 views

scp remote file to local machine [duplicate]

as a part of script I'm trying to copy a file from remote site. But got an error. To me that sounds bit strange as everything sounds ok: #aaa="/path/to/some file with spaces(and brackets).txt" .... ...
0
votes
1answer
20 views

Linux detach from process after certain string

So, I have a command which starts a webserver, it goes step by step and puts output to standard output. It goes like: step 1... step 2... step 3... server up and running on port 9000 However, this ...
1
vote
2answers
25 views

Why can't I capture AWS EC2 CLI Output in Bash?

I am trying to capture the output of an aws ec2 delete-snapshot in a Bash script command but I cannot get anything to capture the output. I have tried result=$(command), result=`command` etc. but when ...
1
vote
1answer
17 views

How to start a tmux within bash right after reboot

I have created a script to run upon reboot of an Ubuntu instance. crontab -e Then added this to the script: @reboot /home/ubuntu/startup.sh This is how the script looks like: #!/bin/bash tmux ...
0
votes
1answer
17 views

Not able to restrict the user to particular directory in unix

Below are the steps I performed: I created group sftponly. Added one user named sftpusers to that group. Added Subsystem sftp internal-sftp to file /etc/ssh/sshd_config Added this line to the file ...
2
votes
1answer
27 views

how to get the desired value in bash shell from the lshw output?

I want to extract the info from lshw output where it says: -cpu product: ...... I want only the product info of this -cpu. How can I do that with awk or sed?
0
votes
2answers
39 views

Shell Script to connect to Database and execute query [closed]

#!bin/bash Query="update table_name set colume ='i' where column_name is NOT NUll" mysql -u username -p password mysql <<EOF $query; EOF The above script is not working
9
votes
0answers
446 views

Why is my Bash script returning a syntax error? [migrated]

I am writing a script which loops into recent files in a folder and executes a command... #!/bin/bash cd /home/Downloads recent_files = ($(ls -t | head -20)) for file in "${recent_files[@]}" do ...
-2
votes
1answer
28 views

Uphold variable life in Bash loop [closed]

I am trying to find the number of files with executable permission by the owner. I am doing this but giving me error cmd> ls -la /myScript.sh myScript.sh is the following z=0 while read line do ...
0
votes
1answer
72 views

Add cronjob with bash script - No crontab for root [duplicate]

I have a deployment script and in it I'm trying to add a cron job. This is the code I am using which I found on stackoverflow. I'm running debian 8. # ADD CRON crontab -l > mycron echo "10 * * * * ...
0
votes
0answers
22 views

Bash variable name is result of concatenation [migrated]

I'm trying to do : declare -a array=(first second third) for i in ${array[@]}; do ${i}_arg=$(some commands here...) done Expected result: first_arg=something1 second_arg=something2 ...
1
vote
1answer
37 views

Bash Script to set Linux OS

I'm working on a bash script and ran into an issue. I'm pushing what I know from using normal if/fi statements and trying to use them to set variables related to picking up the OS version, such as RH ...
5
votes
0answers
98 views

How to check from bash if package exists in debian [migrated]

I would like to make a installation bash script, where I would like to install mysql server. On linux mint I had followed code: apt-get -y --force-yes install mysql-server-5.6 but I installed new ...
0
votes
1answer
46 views

bash script doesn't run properly in crontab but runs fine manually

I wrote a small script to determine the average IOPs per hour in which I later manually convert to a graph and spreadsheet for management to discuss a potential SAN upgrade for an upcoming expansion ...
-1
votes
1answer
31 views

Linux - Print specific line from output [closed]

I am used to working with single line output and can use $1 $4 $8 to specify certain items in that line, but I have never worked with multiple line outputs and would like to just print one line ...
0
votes
2answers
46 views

Print last column containing spaces and special characters

I need a full path/command thats been execued to start a process thats exposed on the network - listens on tcp/udp . I did manage to get all of that using below "one liner": netstat -nlp46|tail -n +3 ...
1
vote
2answers
82 views

password check in bash script calling on expect

Background: I have to copy a file from one server, to over 100 servers in a test environment. once the file is copied, it requires to have the permissions on the file changed/verified. These are all ...
0
votes
1answer
71 views

Nagios bash syntax error

I want to refer with this question to the following post where I got the Skript: Post with Script I'm using Bash 4.1.2(1) and when I try to execute the script, I get following error messages: ...
0
votes
1answer
24 views

Export or Forward /var/spool/mail/USER (readable for customer)

there are some bounce mails in the /var/spool/mail/USER directory that failed to send. Now the customer receives all of those mails from us because he does not have direct access to them. I can ...
1
vote
1answer
52 views

Why is PATH wrong with cron entry? [duplicate]

I have an entry in cron.d: 31 17 * * * root /home/some_user/.bash_profile; /home/some_user/bin/some_script The profile sets a specific path, and I echo the current path in the profile to ensure its ...
1
vote
1answer
26 views

ssh remote command execution quoting

I found this solution that works for me, but I don't understand how it does work given that the sed command encloses its own parameter in single quotes, and the whole ssh command is also passed in ...
4
votes
2answers
498 views

Faster way to ping URL than curl [closed]

What would be the fastest way to check whether the specified URL is working? (responding in OK http status code)? For now I'm using curl, but I have bunch of URLs to test in a loop, so I'm looking ...
0
votes
0answers
41 views

BASH: bash completion function in a custom script

How I can add existing function to a custom script? complete -F _known_hosts test.sh - this works on the command line however when I tried to add this to my custom script it's not working as ...
15
votes
2answers
306 views

How to uninstall newly installed dependencies for a RPM package?

Is there an easy way to make a list of the dependencies a newly installed RPM package will install with yum? Example: If you do yum install ruby then it will also install some rubygems. But when I ...
0
votes
2answers
30 views

Why my netcat connection doesn't send the file correctly?

I wrote this script to send a file using netcat. My intention is to open the netcat port in the destination server from the origin, this way I do everything with just one script instead of having one ...
0
votes
1answer
34 views

convert for loops to while loops comparing arrays

On occasion (like 4 or 5 times in an 8hr shift) I have to check that the sites from being served from a shared server are loading. I currently have a script that does this, however I am using nested ...
0
votes
1answer
48 views

Remote bash script execution via ssh causes local script to stop

I have a setup which behaves in a way i cannot get my head around. So I have a local bash script generateTrafficOnHosts.sh which reads IP addresses from a file. It then calls a bash script ...
0
votes
1answer
55 views

Custom Live Boot PXE ISO Script

Currently I am using an open source PC auditing software called Open-Audit to audit PCs my company receives off lease from school districts. The software uses snmap to pull hardware information over a ...
0
votes
0answers
28 views

How to automatically execute a script after saving it? [duplicate]

I'm developing a bash script and, after every save, i have to switch windows and re-run. Is it possible to execute the script automatically every time the file is saved?
0
votes
0answers
57 views

What is the difference between setting the environment variables in these 2 ways?

For a project I'm working on, we require nginx and lua, and we start it like this: MYVAR1=some_value MYVAR2=some_value /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c nginx.conf And everything ...
1
vote
1answer
74 views

What does a minus sign inside of dollar brackets of a shell script mean?

In an existing shell script, I'm seeing some variables referenced that either include or end with a minus sign. For example: PID=${PID-/run/unicorn.pid} and: run_by_init() { ([ "${previous-}" ...
0
votes
1answer
62 views

Bash linux increment variable

i am trying to increment a variable name inside a for loop to get 4 dynamic variable in each loop, this is an example while read line do for n in `seq 1 4` do ...
0
votes
1answer
212 views

Nginx how to run shell script on page load via lua module os execute and then serve directory listing?

So I have a bash script that I want to execute/run on each "page load" of url so that it will modify (creating symlinks) to a /public/html/ folder that I want the server to then serve. The problem ...
0
votes
2answers
58 views

Can I get an array as an option argument in bash script

I am writing a shell script and wants to pass multiple options in an argument. Is it possible to do that like using getopts? Requirement example: ./shell.sh -d db1 db2 should pass the values db1 ...
-2
votes
1answer
35 views

bash: variable increment does not occur

I have a problem in one of my bash shell scripts. Asked a few colleagues, but they all just shake their heads (after some scratching), so I've come here for an answer. According to my understanding ...
2
votes
2answers
122 views

bash: convert date from to unix timestamp changes timestamp

Running the following command at the xen-servers (either DOM0 or DOMU) at $company gives me a negativ number, on every other system zero (0) (even in my cygwin). date -d "1970-01-01T00:00:00" "+%s" ...
0
votes
1answer
52 views

Logrotate executes postrotate even if file not rotated

I have a problem with my rsyslog and imfile that fails when one of my log file gets truncated.. So to workaround the problem I have modified the logrotate script as follow: ...
1
vote
2answers
25 views

How to cp only into the latest directory name?

mkdir test_dir test_dir1 test_dir2 test_dir3 touch file1 file2 file3 cp -v file* test_dir*/ This copies only to test_dir3 and not in test_dir, test_dir1, test_dir2. Why? For that matter it copies ...
4
votes
3answers
695 views

Is mv with wildcard still atomic

My understanding is that mv dir1/file1 dir2/ is atomic, Is mv dir1/* dir2/ also atomic? As an example, assume there are 10 files in dir1 that are 10GB each.
-1
votes
1answer
57 views

Bash FTP login into Microsoft FTP Service, Invalid command

This is my script. As you can see it executes only 1 command (cd /) after connecting to a remote FTP server. It's very simple... but it doesn't work and give me "Invalid command". I don't understand ...
0
votes
1answer
195 views

FTP file transfer, loop through a directory and copy old files

I would like to move files older than 30 days and copy them into a remote FTP server. I've already written this script, that is able to connect via FTP. Usually, to move files, I would run this ...
0
votes
2answers
54 views

linux-tomcat - add command to startup.sh

How can I add a command at the end of the tomcat startup.sh script to execute a file. I think it is something like this. Assuming my file needs start as command passed to it below: exec ...
0
votes
2answers
65 views

Bash scripting: Using wildcard

I have two different folders. The first one contains symlbolic links named with the names of my servers (for example: udcedpai101). The second one contains the inventory of my servers where the ...
-1
votes
1answer
51 views

understanding the result of this bash script [closed]

I have this simple bash script #!/bin/bash -x for line in `tail /home/user/line` do echo $line done but dont know why it echos all words instead of each line below is output ++ tail ...
0
votes
3answers
34 views

bash variables: expanding the values of variables whose names match a pattern

Let's say in bash I have several variables: POD3_1, POD3_A, POD3_2, POD3_B, etc. Each of the variables names begins with "POD3". Let's say I want to expand the value of all the variables on the ...