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

learn more… | top users | synonyms (1)

1
vote
0answers
20 views

Echo each shell script command with a timestamp

set -x or set -v prints every executed command. How do I get the command printed with the time when the command started executing?
0
votes
3answers
32 views

Doing a backup with mysqldump and drop it on another server (Bash)

I'm using a cron job to do backups hourly and now, I want to drop those backups on another server by default. My script is the following: mysqldump -u db_user -p db_password db_name| gzip > ...
4
votes
0answers
420 views

Inject lines to bash history [migrated]

By default bash loads lines from ~/.bash_history to history. Is it possible to add custom file to be also loaded? I want to inject file containing commands I frequently use and access them it via ...
-1
votes
0answers
17 views

What is the best way to run PHP script every 30 seconds? [duplicate]

I have kind of a special requirement that is, I'm using a Raspberry Pi 2 B device to feed some data to a mysql database in a cloud serve. So I have installed LAMP stack on raspberry pi and config my ...
2
votes
0answers
19 views

Bash prompt: using \[ and \] within PROMPT_COMMAND [migrated]

I'm working on a bash prompt. I'm also trying to create the prompt intelligently, so that it will be easily readable and maintainable. That means not having one huge export PS1. Various sources ...
1
vote
0answers
16 views

get notification when systemd-monitored service enters failed state

I need to have network messages sent when a systemd service I have crashes or is hung (i.e., enters failed state; I monitor for hung by using WatchdogSec=). I noticed that newer systemd have ...
-1
votes
0answers
42 views

Merge (combine) directories using rsync [migrated]

I need to create deploy script to combine directories ├── LIB_COMMON │ ├── file1.php │ ├── file2.php │ ├── file3.php │ └── file4.php ├── LIB_CZ │ ├── file2.php │ ├── file3.php │ ├── ...
1
vote
3answers
57 views

Create tar file on Solaris and untar the file on Linux is it right?

I want to create tar file on Solaris (Solaris 10 ) as Kit.tar and untar the Kit.tar on Linux machine ( linux red-hat 3/4/5 ) Can we be safe with that untar process on Linux machine? , I want to be ...
1
vote
0answers
36 views

Delete files that are not part of a bash array [migrated]

Right now I backup the mysql databases using a cronjob everyday. Now that the server is getting full, I only want to keep one backup for every month, one backup from sunday every week and the last 7 ...
0
votes
0answers
8 views

How can I change readline settings on keypress? [migrated]

I checked docs for readline (in man bash), and I can't find a way to solve one problem: how to change readline setting (set ... on/off) on keypress? Keybindings seem to have form: key:function or ...
4
votes
1answer
103 views

Running detached screen session but without termination in the same bash

Here are already many questions like this, but every one recommends (a variant of) the following solution: screen -dmS somename bash -c "/path/to/script; bash -l" e.g. when the script ends, run an ...
2
votes
1answer
26 views

Command 'getent'

Part 1 Is getent supposed to be an executable? In my zsh setup, I can see getent is actually defined as a function $ which getent getent () { if [[ $2 = <-> ]] then grep ...
0
votes
1answer
45 views

System Information on terminal

This might come across as a silly question but is there any shell that will allow me to get the system information as the shell is active? What I mean is a shell like bash or similar that will show me ...
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
25 views

Free Nas Cron Job not finishing [closed]

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
32 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
46 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
37 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
24 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
38 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
19 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
18 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
29 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
42 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
89 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
40 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 ...
0
votes
1answer
48 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
32 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
48 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
90 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
73 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
25 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
29 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
507 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
44 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
309 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
31 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
40 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
55 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
59 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
59 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
77 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
67 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
239 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 ...