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

learn more… | top users | synonyms (1)

-1
votes
0answers
6 views

celery monitoring - how to do it

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
42 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
60 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
935 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
23k 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
1answer
33 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
83 views

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

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
670 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
2answers
34 views

How to send custom signal to bash daemon process?

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
14 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
41 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
0answers
27 views

Bash script to get the non installed volume [closed]

I'm trying to make a linux script that automaticaly installs the new added volumes,to do so i need to get the non installed volume's name. Is there any script that returns the non insalled volumes ...
2
votes
5answers
6k 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
655 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
26 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
10k 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
148 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
53 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
27 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
45 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 ...
3
votes
4answers
35 views

Bash evaluation baffling

I'm trying to get a script to do something when one number is bigger than another, in this case, when the system load average exceeds a defined value. All of it is working aside from the evaluation ...
14
votes
7answers
10k views

How do I ask screen to behave like a standard bash shell?

Just learned about the screen command on linux - it is genius. I love it. However, the actual terminal/prompt in screen looks and behaves differently than my standard bash prompt. That is, the ...
1
vote
1answer
32 views

Is using su to drop root in shell scripts a security risk?

When searching for how to drop root permissions in shell scripts, I often see answers using su. However, when you're done using su you can just type logout and be back at the shell of the original ...
0
votes
3answers
50 views

Load users environment variables in a cronjob

How can I load the users environment variables in a cronjob? I have a cronjob which should start a script every minute on my Ubuntu machine: * * * * * /home/user/myscript.sh; In this script I ...
13
votes
7answers
12k views

How can I determine what is taking up so much space?

I was using df -h to print out human readable disk usage. I would like to figure out what is taking up so much space. For instance, is there a way to pipe this command so that it prints out files that ...
1
vote
0answers
21 views

how to filter sar -d disk output tidily

sar -D output-I would like a suitable command to run alongside stress -hdd but this is the output which sar -D 1 10 gives. I have filtered it using both awk |'NR > 1 {printf ...