bash

How to separate words in a "sentence" with spaces?

Background Looking to automate creating Domains in JasperServer. Domains are a "view" of data for creating ad hoc reports. The names of the columns must be presented to the user in a human readable fashion. Problem There are over 2,000 possible pieces of data from which the organization could theoretically want to include on a report....

Check whether a certain file type/extension exists in directory

How would you go about telling whether files of a specific extension are present in a directory, with bash? Something like if [ -e *.flac ]; then echo true; fi Thanks ...

Sudo - is there a command to check if I have sudo and/or how much time is left?

See title. I want a command that lets me query sudo. Ideally it would return success if I still have sudo and false if sudo has expired. Getting the time left might also be useful (although if I was concerned I could just do sudo -v to revalidate.) Oh and it shouldn't have to ask for a password. The closest thing I've found is "su...

getting aliases from config by regular expression (bad separated)

Hey guys, I tried to get some aliases from a specific config file in a short bash script. The config looks like: [other config] [alias] alias: command -o option alias2: command -l 2 alias3: command -o option [other config] How would you get these aliases separated? I would prefer a output like this: alias: command -o option alias...

Why does bash in posix mode fail to chase my symlinks?

I'm seeing weird behavior when I run "ssh " to a Linux system. I tracked it down part way to a difference in bash when started in posix mode. % bash --posix % ln -s /tmp mytmp % cd mytmp % pwd /home/user/mytmp The bash man page has these items under posix mode: --> When the cd builtin is invoked in logical mode, and the pathname con...

Creating a symbolic link in a bash script in a different folder

My bash script is getting two arguments with folders (that exist and everything). Inside the first one I want to create a link to the second Suppose I have the folders /home/matt/a and /home/matt/b, I call the script like this : /home/matt # ./my_script ./a ./b I want to see a symbolic link inside a that points to b And of course, ...

zsh give file argument without creating a file - syntax?

Suppose I have have a program P which has a filename as argument. For example P file reads the file "file" and does something with it. Now sometimes the content of "file" is very small, e.g. just one line. So instead of creating a file f with that line and calling P f I want to give the content of line directly as an argument t...

How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?

I have created a linux service that runs as a deamon (and gets started from /etc/init.d/X). I need to set some environment variables that can be accessed by the application. Here's the scenario. The application is a bunch of Perl AGI scripts that depend on (and therefore need to run as) asterisk user but asterisk doesn't have a shell. I...

Sorting files into directories based on their name

I have a few directories that contain a lot of files. As some of them are approaching 600k files, they have become a major pain to handle. Just listing the files is slowly becoming a major bottleneck in the applications processing them. The files are named like this: id_date1_date2.gz I've decided to split the files into several smaller...

with sequential calls to $R CMD or $R --vanilla, do I have to reload libraries in each R script?

I would like to run a sequence of R scripts from the bash command line. Can I keep the R session 'open' between calls? Or do I have to save and load objects and re-load the libraries in each script? Thanks in advance ...

tcpdump - ignore unkown host error

Hey folks, I've got a tcpdump command running from a bash script. looks something like this. tcpdump -nttttAr /path/to/file -F /my/filter/file The filter file has a combination of ip addresses and host names. i.e. host 111.111.111.111 or host 112.112.112.112 and not (host abc.com or host def.com or host zyx.com). And it works grea...

JVM Tuning with JAVA_OPTIONS using a space?!?

Okay, so I'm adding an argument to my JAVA_OPTIONS as documented here. However, it is not working because of the space. Here is the line I am using in the UNIX shell script (just as the documentation specifies): JAVA_OPTIONS="-DFRAMEWORK_HOME=${app_home}/conf -Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0 ...

Test for non-zero length string in bash: [ -n "$var" ] or [ "$var" ]

I've seen bash scripts test for non-zero length string two different ways. Most scripts use the -n option: #!/bin/bash # With the -n option if [ -n "$var" ]; then # Do something when var is non-zero length fi But the -n option isn't really needed: # Without the -n option if [ "$var" ]; then # Do something when var is non-zero len...

Putty closes on executing bash script

I am writing my first ever bash script, so excuse the noobie-ness. It's called hello.bash, and this is what it contains: #!/bin/bash echo Hello World I did chmod 700 hello.bash to give myself permissions to execute. Now, when I type exec hello.bash My putty terminal instantly shuts down. What am I doing wrong? ...

.profile: line 31: syntax error: unexpected end of file

I'm bad at bash programming. Where is the error? Here is my .profile file: # WARNING: For help understanding this file, and before you try # to change any of it, type "man .profile" and read carefully. # # # Set command search rules # if [ -x /bin/showpath ] ; then       export PATH; PATH=`/bin/showpath $HOME/bin /u/cs350/sys161/bin ...

If grep fails delete the file

Heya guys, I have this small script and i need to grep all the files and leave only the ones that contain a keyword and I'm stuck on this, any help in pointing out my dumb errors is appreciated :) #!/bin/bash server=(server1...server24) . . . for ((n=0; n <= 24 ; n++)) do if grep -q "KEYWORD" directory/${server[$n]}.html ; th...

How to tell bash that the line continues on the next line

Hi, in a bash script I got from other programmer, some lines length exceeds 80 columnds or more. What is the character or thing to be added to the line in order to indicate that the line continues on the next line? Thanks ...

BASH - Make the first Letter Uppercase

I try to capitalize the first letter in a CSV which is sorted like this: a23;asd23;sdg3 What i want is a output like this a23;Asd23;Sdg3 So the first String should be as is, but the second and third should have a capitalized first letter. I tried with AWK and SED but i didn't find the right solution. Can someone help? ...

How can I replace the same string several times with different random values in Perl?

I'm using this Perl one-liner (in bash) to successfully replace a string with a random one, in a given file: perl -pi -e "s/replace\ this/`</dev/urandom tr -dc A-Za-z0-9 | head -c64`/g" example.php However, I don't know how to replace several "replace this" with different random strings. ...

How to set site in maintenance mode trough shell-script?

For my next project I will use automatic deployments with git. I can run a shellscript before and after deployment. Is it possible to set "maintenance" automatically with shell? In my .htaccess then I would check if a server variable is set to deployment or not to do the rewrite to maintenance? Is this possible and how should I handle ...