bash

awk : multilines output fr single string w easy looking replacement

000 000 000 000 (4 fields each of which is a group of 3 zeros separated by a space) Process to generate 4 new lines 100 000 000 000 000 100 000 000 000 000 100 000 000 000 000 100 On ea line a group of three zeros is replaced by 100 How can I do this ? tom ...

Redirect streams for prompting passwords

Hi, I have a script that prompt for a password to achieve a specific task. I wanna skip entering password each time. for this, i thought about sth like that: ./myscript < my_file_containing_pass but unfortunatly, this doesn't work. any idea? ...

bash script - DB2 "db2 restore database" default answer YES

Hi, I'm trying to make a bash script that's going to backup a db2 database and then restore it into a different database. The problem is that DB2 asks a (y/n) question, and I can't get an auto answer for it to work - it needs a y and carriage return. I've tried the following line (and the yes command) tho it doens't work #while true; d...

Executing scripts using more users

I'm writing a bash script which calls a lot of other scripts. Several scripts have to be executed as user_1 but several ones as user_2. The scripts should be called in strict sequence. I start my script as user_1 and use su many times to become user_2. These times su requires a password so I have to retype it many times. I'd like to avoi...

Bash: append text to last line of file

How can I add a percentage symbol % to the end of the last line in a text file? I do not want the % to be on a new line, it must be at the end of the last line. Thanks! ...

Automation of Open Zoom

How would I automate the process of deploying a gigantic jpeg on a web server and then generate the necessary files to load the image up on the frontend site in OpenZoom? I'm working in php but any shell/bash/python scripts are welcome ...

Creating a script from a complex bash command

I need to run the following command in a folder containing a lot of gzipped files. perl myscript.pl -d <path> -f <protocol> "<startdate time>" "<enddate time>" -o "0:00 23:59" -v -g -b <outputfilename> My problem is that the command does not take gzipped files as input. So, I would need to unzip all those gzipped files on the fly and...

Extracting multiple parts of a string using bash

I have a caret delimited (key=value) input and would like to extract multiple tokens of interest from it. For example: Given the following input $ echo -e "1=A00^35=D^150=1^33=1\n1=B000^35=D^150=2^33=2" 1=A00^35=D^22=101^150=1^33=1 1=B000^35=D^22=101^150=2^33=2 I would like the following output 35=D^150=1^ 35=D^150=2^ I have ...

bash scripting - selectively handle file names with spaces

I have a directory with the files names as "a b c.jpg", "d e f 0.jpg", "g h i.jpg" I need a script to have all the files ending with "0.jpg" to become "_0.jpg" So, in the above example the second file should become "d e f_0.jpg" ...

Bash script for generating ssh keys

Hi, I would like to create script, which simply runs ssh-keygen -t rsa. But how to pass to it 3 times enter? ...

Bash stderr and stdout redirection failing

I have a FORTRAN program output I want to redirect to file. I've done this before and use $myprog.out>>out.txt 2>&1 and for some reason this is not working. I test it with a another simple test program $myprog.test>>out.txt 2>&1 and it works I run myprog.out and the output goes to screen as usual but redirecting it seems to fail! ...

Python 'source HOME/.bashrc' with os.system()

I am writing a python script (Linux) that is adding some shell aliases (writes them to HOME/.bash_aliases). In order to make an alias available immediately after it was written I should issue the following bash built-in: source HOME/.bashrc source is a bash built-in so I cannot just: os.system(source HOME/.bashrc) If i try somethi...

shell script to find filename & line count of each file, now insert this record into Oracle table.

Hi, I have to find the filename available in a folder with each file line count. And then, i will have kind of two column data. Now i have to insert this record into a oracle table having two column(col1, col2). Can i write a shell script which will do both. I found here itself of writing the first part. i.e wc -l *| egrep -v " ...

NSTask with bash script problem

For example, i have this simple bash script: #!/bin/sh cd $1; And this cocoa wrapper for it: NSTask *cd = [[NSTask alloc] init]; NSString *testFolder = [NSString stringWithString:@"/Users/test/Desktop/test 1"]; [cd setLaunchPath:@"/bin/sh"]; [cd setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] ...

extracting nested different types of archives from different folders

Hi, I have got an archive of many fonts but i have troubble extracting them all into one folder. i tried to write a long script for 3 hours now, it somehow breaks on a path issue. i tried piping like find . -name *.zip|unzip -d ~/fonts but it doesnt work. i changed so much in the script i wrote, that it is not really presentable :(. eac...

Quoting in a bash variable assignment

Using the following simplified code extract: DIR='a b' mount_command="./mount.cpfs $loop $DIR -f $OPTS" sudo $mount_command Executes this line when trace is on: + sudo ./mount.cpfs /dev/loop0 a b -f -o default_permissions,allow_other,attr_timeout=0 But DIR is not quoted, and so a and b are passed as different parameters, rather tha...

How do you return to a sourced bash script?

Hi, I use a script that extends using the bash source feature; #!/bin/bash source someneatscriptthatendsprematurely.sh I would like to be able to return from that script, without breaking the main script. Using exit breaks the main script, return is only valid in functions and experimenting with $(exit 1) does not seem to work eith...

Storing sudo password as variable in script - is it safe?

Is storing my password this way safe? echo 'Write sudo password (will not be displayed) and hit enter' read -s password I need it to make commands like this: echo $password | sudo -S apt-get install -y foo bar ...

linux shell script to add leading zeros to file names

I have a folder with about 1700 files. They are all named like 1.txt or 1497.txt etc. I would like to rename all the files so that all the filenames are 4 digits long. IE 23.txt becomes 0023.txt. What is a shell script that will do this? Or a related question: How do I use grep to only match lines that contain \d.txt (IE 1 digit, t...

bash script to append string to multiple files in same directory

Is there a way to write a BASH script that will append a string to every file in a directory? e.g., I want to append the string "test" to every .html file in the current working directory I'm in; something like: echo "test" >> *.html But of course this doesn't work. ...