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

learn more… | top users | synonyms (1)

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 ...
38
votes
9answers
13k views

How can I run arbitrarily complex command using sudo over ssh?

I have a system that I can only log in to under my username (myuser), but I need to run commands as other user (scriptuser). So far, I have come up with the following to run the commands I need: ssh ...
2
votes
1answer
142 views

How to find full process arguments and associated listening ports?

I can execute netstat -atulpn | grep java to find all Java processes with their accompanying ports, which is great, however I would like to also have the processes full execution arguments also shown. ...
25
votes
8answers
28k views

How to add a timestamp to bash script log?

I have a constantly running script that I output to a log file: script.sh >> /var/log/logfile I'd like to add a timestamp before each line that is appended to the log. Like: Sat Sep 10 ...
1
vote
3answers
56 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 ...
-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 │ ├── ...
22
votes
3answers
3k views

In Bash, are wildcard expansions guaranteed to be in order?

Is the expansion of a wildcard in Bash guaranteed to be in alphabetical order? I am forced to split a large file into 10 Mb pieces so that they can be be accepted by my Mercurial repository. So I was ...
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 ...
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 ...
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 ...
0
votes
1answer
42 views

different interactive and non-interactive shells

A user account has it's shell defined in passwd file as bash. I would like to change this user account's shell to tcsh for non-interactive jobs (like ssh ), but keep interactive shell to bash. Is ...
0
votes
2answers
1k views

How to delete all ufw rules for a certain port?

I am using ansible to configure ufw on my DB servers to only let accept connections from certain servers connection to a specific port (lets say 1234). When a server that used to have access is taken ...
10
votes
5answers
19k views

How to remove invalid characters from filenames?

I have files with invalid characters like these 009_-_�%86ndringshåndtering.html It is a Æ where something have gone wrong in the filename. Is there a way to just remove all invalid characters? ...
42
votes
7answers
26k views

How to create a UUID in bash?

In Java i can create a new random UUID with UUID uuid = UUID.randomUUID(); I now need to do the same within a bash script. Is there a command or library I could use?
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 ...
1
vote
1answer
904 views

Dovecot quota-warning.sh not being excecuted

I would like to run a custom script with dovecot once the user reaches certain percents of their quota. The issue is that no matter what I try dovecot does not seem to execute my bash script. ...
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 ...
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" ...
6
votes
4answers
8k views

How to parse and convert ini file into bash array variables?

I'm trying to convert an ini file into bash array variables. The sample ini is as below: [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these become: ...
2
votes
2answers
785 views

Proper Bash Daemon Script Creation

On Ubuntu, I copied /etc/init.d/skeleton as a new file and made it "all" executable (just like the others in that directory). In it, I made a "foo" that was just another Bash script in /usr/sbin, but ...
-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 ...
2
votes
1answer
1k views

Linux- Permission denied?

I'm installing Neo4j server as a linux service, but when I install it, I get the following message: /sbin/insserv: Permission denied What is this? What should I do? I'm running everything with ...
2
votes
1answer
163 views

Bash Function to Export .bashrc to a Remote Server

I am trying to write a bash function shown below. I am trying to scp my .bashrc to the target machine. I want to do modify the following function in the below two ways. I want to enter the password ...
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 ...
7
votes
7answers
4k views

In *nix, how to determine which filesystem a particular file is on?

In a generic, modern unix environment (say, GNU/Linux, GNU/Solaris, or Mac OS X), is there a good way to determine which mountpoint and filesystem-type a particular absolute file path is on? I ...
-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 ...
3
votes
3answers
32 views

Is it possible to determine if a job is being started as an at job (kicked off via atd/cron)?

Is there a way to identify a script is being run as an at job instead of interactively from the shell by a user? Some of our scripts have a guard to check if they're running in screen by checking ...
4
votes
1answer
5k views

smtp.gmail.com from bash gives “Error in certificate: Peer's certificate issuer is not recognized.”

I needed my script to email admin if there is a problem, and the company only uses Gmail. Following a few posts instructions I was able to set up mailx using a .mailrc file. there was first the error ...
-1
votes
1answer
67 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
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" .... ...
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
3answers
1k views

Completely reset PostgreSQL to default?

Question Is there a way to completely reset a PostgreSQL installation on Linux, so it is in the same state as when I installed it? Idea I have considered rm -rf /var/lib/pgsql/* rm -rf ...
4
votes
4answers
1k views

Pipe stderr and stdout to different commands (not just to files)

I'm making a backup script for ldap. I want the errors to go to a file in /var/log and the output to go to another file in the backup folder. Currently I'm redirecting to a temp file and then sending ...
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 ...
5
votes
3answers
14k views

bash: variable loses value at end of while read loop

I have a problem in one of my 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 the ...
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?
2
votes
1answer
1k views

Calculate average of every 5 samples with rrdtool or other languages

I want to make an average of 5 samples and calculate a single value: Current output - I put resolution of 5 minutes but receive 5 samples: $ rrdtool fetch file.rrd AVERAGE -r 300 --start 1200000000 ...
0
votes
1answer
1k views

Improper output in SSH session on OSX using FreeSSHd on Windows with cygwin bash/sh shell

I am testing out running an SSH server on a local Windows VM. I have installed FreeSSHd and set the command shell to "c:\cygwin\bin\sh --login -i" (bash as well) with "Use new console engine" ...
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 ...
0
votes
1answer
105 views

Mass disable customers in OTRS

The problem is about OTRS customers. I can't use an external customer backend, so I want to update the customer DB via CSV files. I already wrote a script to add new Customers via ...
2
votes
5answers
2k views

Run local script over ssh

silent ssh is setup from server A to server B (and some 500 other servers) I have written a script on server A (shell and perl) that I want to execute via ssh on server B (and the other 500 servers). ...
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
5answers
11k views

ssh to multiple hosts and sudo multiple commands

I need to loop through and ssh to multiple hosts and run a series of commands on each. something like: for i in $(jot -w '%02.0f' 14 1) >do ssh user@host$i sudo -i "command1; command2; command3" ...