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

learn more… | top users | synonyms (1)

-1
votes
1answer
26 views

Linux - Print specific line from output [on hold]

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
39 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
44 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
58 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
13 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 ...
0
votes
1answer
41 views

why is PATH wrong with cron entry

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
0answers
20 views

Recover last argument of the last command in bash' vi mode [migrated]

When using bash's vi mode (set -o vi), is it possible to recover the last argument of the last executed command? This is done in emacs mode with ESC + . , and I would like to do it in vi mode as well. ...
0
votes
0answers
13 views

Remap cursor keys in bash vi mode to <nop> (disable cursors) [migrated]

When using vi mode (set -o vi) with Bash, is it possible to remap the cursor keys to so that they don't work (and be forced to use h, j, k and l movement keys)? Under vim (the editor), I can do it ...
1
vote
1answer
17 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
475 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
35 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 ...
13
votes
2answers
287 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
23 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
24 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
21 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
35 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 ...
-1
votes
0answers
32 views

How to include single quotes in bash folder expansion? [migrated]

Edited* I have the following definitions in my bash script: DATE_SUFIX=$(date +%F_%H-%M-%S) NAME="MyBackup_" FILE_NAME=$NAME$DATE_SUFIX TMP_DIR="/tmp/" TMP_BKP=$TMP_DIR$NOME_ARQ"/" TAR_CMD="tar czPf ...
0
votes
0answers
28 views

VNC/SSH: How to execute a command after logging in? [migrated]

I'm looking for a way to create a VNC console user that executes the command screen or bash immediately after logging in so they get their own restricted shell for executing commands etc. Screen/bash ...
1
vote
0answers
55 views

Why do I get different results with the same user and the history command? [migrated]

I work with Linux for quite some time and have seen this behaviour but I never got a good explanation. Probably it's even very simple. If I login twice with the same user (bash) in the same server ...
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
46 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
61 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-}" ...
4
votes
0answers
154 views

Persistent Bash Prompt Prefix Linux [migrated]

I want to have the FQDN as bash prefix instead of just using the hostname. So I can change root@web: ~$ to root@web.domain.tld: ~$ I already know that that is possible by using: ...
0
votes
1answer
54 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
115 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 ...
-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 ...
0
votes
2answers
53 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
29 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
72 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
34 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
24 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
685 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
38 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
128 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
43 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
56 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
47 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
29 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 ...
-1
votes
4answers
159 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) ...
-1
votes
1answer
51 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 ...
1
vote
1answer
35 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
56 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 ...
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 ...
1
vote
0answers
26 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 ...
1
vote
1answer
51 views

How to make a simple script that increases a number character by 1

I have to add a single command for MANY vlans, and wondering if I can generate a simple text file somehow? Then I can simply paste the text file into the network switch and it will add the needed ...
1
vote
1answer
41 views

How can I know the absolute path of a running process? on solaris

this is the command to view the process path on Linux ps -auxwe | grep 24466 ( 24466 is only example ) but please advice is it possible to view the path of running process on Solaris if yes ...
0
votes
1answer
60 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
1answer
20 views

Should I be adding aliases to /etc/profile instead of /etc/basrhc?

I've been adding them to /etc/basrhc, and that works most of the time. But I noticed that when I su to another user, I lose all my aliases. It turns out that /etc/bashrc is only loaded when the ...
0
votes
1answer
25 views

Resolve packages not found and errors during configure,make,make install in a script

I need to have a script that will install a package from source in a Linux system and need to know how to take care of the errors that usually come up as a result of the first step ./configure maybe a ...