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

learn more… | top users | synonyms (1)

4
votes
3answers
18k views

How to save + close file when editing in bash?

OK - I am linux newbie - I am trying to edit a file from bash via edit <filename> command in whatever the default mode is (I am assuming 'vi'?). Problem is for the hell of me I cannot how to ...
0
votes
1answer
11 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 ...
14
votes
17answers
41k views

Shell Command for Getting IP Address?

Is there a bash command to find the IP address for an Ubuntu box? I need to find the IP address so I can ssh into the machine later.
-2
votes
0answers
28 views

Scripting a menu with selection indicator in bash [migrated]

I'm really new in bash scripting and I'm currently automating my project creation process. I've done a lot of work right now but i'm thinking about changing my installation plugins part... Could ...
-2
votes
0answers
50 views

Syntax Error: unexpected end of file — Bash script [migrated]

I am trying to create an spritz app! Everything was working fine, but since yesterday I keep getting this error: ./spritz: line 176: syntax error: unexpected end of file I have checked the script ...
1
vote
1answer
905 views

Problems in monitoring file age with nagios (command substitution in filename)

In my current nagios installation I check for the existence of a remote backup through NRPE. In particular, my remote nrpe.cfg (on a Ubuntu 8.x) is: ...
2
votes
3answers
539 views

Passing variables problem - Bash

I have a following problem: #!/bin/bash NUM=`cat accounts | wc -l`; for i in {1..$NUM} do account=`awk "NR==$i" accounts`; echo -e "\nAccount: $account\n"; sudo ./backup_maildir $account; ...
-1
votes
0answers
9 views

celery monitoring - how to do it [on hold]

Do you know of a way that I can monitor the status of tasks that are running on celery? I want to know if some tasks have failed or succeeded and send a mail to me. Ideally I want to do this in bash.
74
votes
9answers
103k views

How do I get current Unix time in milliseconds using bash?

How do I get the current Unix time in milliseconds (i.e number of milliseconds since Unix epoch January 1 1970)?
0
votes
2answers
44 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 ...
0
votes
1answer
69 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 ...
20
votes
5answers
936 views

What could make `>` silently fail in Linux?

I ran this command: python ./manage.py dumpdata partyapp.InvitationTemplate > partyapp_dump.json To dump data into the partyapp_dump.json file. But all the data just gets printed on the screen ...
23
votes
7answers
24k 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 ...
3
votes
3answers
3k views

How to delete empty source directories when moving folders with rsync?

rsync can be coaxed into moving folders very similarly and superiorly to traditional mv with the following options: rsync -axvvES --remove-source-files source_directory /destination/ However one ...
-1
votes
0answers
37 views

ubuntu script two different outputs [duplicate]

So I have a script that checks with curl if a website is redirect. If the website is redirected, an e-mail will be sent. If the website is not redirected, an if-statement is called where I get the ...
15
votes
5answers
12k views

Bash Scripting: Require script to be run as root (or with sudo)

I'm trying to write a bash script (in Ubuntu) that will backup a directory using tar. How can I do a check in the script so that it can only be run as root (or with sudo)? For instance, if a user ...
0
votes
2answers
85 views

can't execute sudo in a php script ran from http [closed]

I am not able to run any sudo command in any exec call from php script if the php was execute from the browser. However if the same scripts runs under bash shell, it works just fine. I suspect there ...
4
votes
2answers
673 views

rsync not removing single quotes around array of strings --filter list

Trying to safely retrieve files from heavily infected Windows XP and 2003 machines that came to us from an acquisition. I have a similar need for automating a script that would run on PXE booted ...
-1
votes
0answers
37 views

How to send custom signal to bash daemon process? [migrated]

I have simple bash daemon running (with root privileges ) in background which suppose to do action1 or/and action2 when notified. How do I notify it/send some kind of signal on which it will react? ...
3
votes
4answers
2k views

How to get the mount point of flash drive by using uuid?

I am beginner in ubuntu linux and i need to write simple bash script, that can identify necessary flash drive(which contains only one vfat partition) using uuid of this partition, and get the mount ...
0
votes
0answers
17 views

Delete folders which not match a list [migrated]

I need practical example how get rid folders which are not in the list in UNIX. So i do not need to compare its contents or md5sums, just compare folders names. For example, one folder has few ...
0
votes
0answers
10 views

How to correct malfunctioning Terminal in Mac [migrated]

Terminal commands like ls, sudo, cp, mv, rm are not recognised in my Mac terminal. I face this problem after I edited the .bash_profile file. (I installed Tomcat and added PATH and CATALINA_HOME ...
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
27 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 ...
-3
votes
1answer
41 views

Display only some of the lines of the lsof command [closed]

I am trying to create a bash script for displaying only certain lines of the lsof command. I have figured out that the lsof command itself lists information in the form of columns which show info ...
-6
votes
0answers
53 views

Linux 'w' command, get IDLE time in seconds [migrated]

I need to get idle time of all users in seconds (not minutes or days), how do i go about doing it ? This command lists the idle times of all connected users : w | awk '{if (NR!=1) {print $1,$5 }}' ...
-1
votes
0answers
9 views

How do I perform xargs grep on grep output that has spaces? [migrated]

I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like #Find all C++ files that match a certain pattern ...
0
votes
1answer
18 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: ...
2
votes
2answers
46 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" ...
31
votes
6answers
20k views

Merge 2 directory trees in Linux without copying?

I have two directory trees with similar layouts, i.e. . |-- dir1 | |-- a | | |-- file1.txt | | `-- file2.txt | |-- b | | `-- file3.txt | `-- c | `-- file4.txt `-- ...
2
votes
5answers
7k views

shell script: run a batch of N commands in parallel, wait for all to finish, run next N

Task: run blocks consisting of 3-5 commands (in parallel/background). Example block: dd if=/dev/urandom of=/mnt/1/x bs=1024 count=1024000000 & dd if=/dev/urandom of=/mnt/2/x bs=1024 ...
4
votes
3answers
659 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
vote
2answers
23 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 ...
-1
votes
1answer
28 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 ...
12
votes
5answers
11k views

Force SSH to use a specific shell

Is there any way to force SSH to use a particular shell on the remote end, regardless of what the user's default shell is? I've tried solutions akin to: ssh host.domain.com /bin/bash -c ...
4
votes
4answers
7k views

BASH Scripting, su to www-data for single command

I am working on automating the creation of subversion repositories and associated websites as described in this blog post I wrote. I am running into issues right around the part where I su to the ...
-1
votes
0answers
6 views

remove ^M from solaris by perl one liner on the same file [migrated]

usually in order to remove the ^M from file we do dos2unix test.txt test.txt tr -d ‘\r’ <old.file > <new.file> but this approach insist to create new file if we not want to create a ...
6
votes
1answer
426 views

Bash script parameters

I need to write a bash script, and would like it to parse unordered parameters of the format: scriptname --param1 <string> --param2 <string> --param3 <date> Is there a simple way ...
1
vote
0answers
25 views

Parsing part of a file name to use as a variable in bash [migrated]

I need to get the DB name and use it as a variable from part of a file name. Currently I have it pulling in the name of the file from a ls command. This is what it returns: Test-20150311-1200.sql I ...
-1
votes
4answers
150 views

How to test if two given files are identical?

Just updated the code... I get out everytime on the "else" sequence. You can download the update.sh file from my server. it only contains echo "Hallo update" Updated code (03.11.2015) ...
0
votes
1answer
54 views

Straight forward way to run ssh-agent and ssh-add on login via SSH?

I'm trying to have the following commands be auto-executed when I login to my server via ssh: ssh-agent /bin/bash ssh-add ~/.ssh/id_rsa My ssh key has a passphrase and I'm fine with entering it ...
0
votes
0answers
31 views

Advanced Wget usage [migrated]

I have a list of about 200 servers which contain links to individual files, for this question, let's just pretend they're .txt files. I need to download every file, however some servers only have the ...
0
votes
0answers
38 views

Is shell parent of all the processes in linux [migrated]

I have been trying to understand shell scopes and environment in depth. I have been reading about how if we do export VARIABLE=VALUE it will be available in subshell. So I wanted to ask a question I ...
0
votes
2answers
50 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 ...
0
votes
3answers
26 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 ...
0
votes
1answer
28 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 ...
1
vote
2answers
27 views

Find process with most TCP sockets?

How can I find the process with the most TCP sockets that is currently running with bash ? I would like to only output the process name
14
votes
1answer
12k views

Check if array is empty in Bash

I have an array which gets filled with different error messages as my script runs. I need a way to check if it is empty of not at the end of the script and take a specific action if it is. I have ...
-1
votes
1answer
46 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 ...
-1
votes
1answer
46 views

SED multiline recursive find and replace [duplicate]

I have a large number of sites with the same bit of php inserted in all files that contain footer in their filenames. //###==### malicious code //###==### How to use SED or another command to ...