Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

1
vote
2answers
49 views

Escaping a linux command

I'm trying to run a command from a script I wrote that basically replaces a string in file vzctl exec VZID sed -i 's/\/>/address="$IP\/255.255.255.0"\/\>/' "file.xml" The problem is the ...
7
votes
2answers
540 views

How to replace spaces in all file names with underscore in Linux using shell script?

I tried following shell script which should replace spaces from all xml files for xml_file in $(find $1 -name "* .xml" -type f); do echo "removing spaces from XML file:" $xml_file mv "$xml_file" ...
2
votes
2answers
36 views

How do I write a script to automatically optimize all the PNGs in my MediaWiki images directory?

I have MediaWiki 1.25.2 installed on my 64-bit Debian 8.1 VirtualBox machine and I'd like to be able to upload the images/ directory from this installation to my DropBox. Being a cheapskate I'm trying ...
-1
votes
1answer
29 views

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

I wrote a shell script which reads some files and copy all the data from these files to other consolidated file. This happens multiple times and previously copied data will not be copied again. For ...
1
vote
0answers
40 views

bash “no such file or directory” when sh symlink works! [closed]

I use tcsh on a Centos 6.5 64-bit system. I created a file x.sh with two lines: #!/bin/bash echo Yes yes That's it. Then did chmod +x x.sh. # ./x.sh /bin/bash: ./x.sh: No such file or directory ...
0
votes
0answers
24 views

Get the list of packages that are not installed on a Debian system

I am writing a script to print the list of packages which are not installed. #!/bin/bash declare -a LIST_OF_PACKAGES=("php5" "nginx") for i in "${LIST_OF_PACKAGES[@]}" do ...
-1
votes
1answer
19 views

How to select from 2 numbers in a script?

I=1 APPCNT=$(itemCount $APP_LIST ,) while [ $I -le $APPCNT ] ; do APPNO=$(itemGet $APP_LIST $I ) APP_List=6,9 APPNO=6,9 is coming instead of 6 only or 9 only. What can I use instead of ...
0
votes
1answer
35 views

tail file from remote server and nslookup on local

I need a script for resolve hosts. For now I run this script on local machine for i in `tail -F access.log | awk '{print $8}' | awk '{gsub("http://|/.*","")}2' | awk '{gsub("http://|:.*","")}1' | ...
1
vote
1answer
35 views

search and increase the values between the second tilde symbol and the 3rd tilde symbol in each line of a txt file

I was wondering is there any way to search and increase the values between the 2nd tilde symbol and the 3rd tilde symbol in each line of a txt file. Maybe vi can do this? For example, i have a ...
2
votes
2answers
99 views

Save list of echo outputs to .txt

I'm having a lot of trouble at work trying to save a long list of echo outputs as a .txt file on my desktop. I am using Bash in Yosemite 10.10.4. I am still very new to Bash so any help and tips are ...
0
votes
1answer
28 views

How to append extension to files with certain filename format

I have several files generated by a script but I neglected to have the script append a file extension. Each filename contains the substring k120 and no other file in the directory contains that ...
0
votes
2answers
49 views

Get number of files in each directory [duplicate]

I have a directory with a very large number of subdirectories (~800) that were generated programmatically. I want to get a count of the number of files in each of these subdirectories to check for ...
11
votes
4answers
562 views

Fast method of splitting string from textfile?

I have a two text files: string.txt and lengths.txt String.txt: abcdefghijklmnopqrstuvwxyz lengths.txt 5 4 10 7 I want to get the file >Entry_1 abcde >Entry_2 fghi >Entry_3 jklmnopqrs ...
0
votes
2answers
26 views

how to print tilt char in awk

I have a file str.txt with the following sample records. 31,2713810299,1,11-Aug-15 19:52:10 32,2713810833,1,11-Aug-15 21:36:18 Now I want to print output with awk as below. cat str.txt|awk -F, ...
-2
votes
3answers
102 views

Why the builtin `test` fail with 'less than' (<) and 'greater than' (>)?

This code: #!/bin/bash if [ "4" = "a" ]; then echo "equal"; fi if [ "4" > "a" ]; then echo "yes 1"; fi if [ "4" < "a" ]; then echo "yes 2"; fi echo "exit" prints this three lines: yes 1 yes ...
1
vote
2answers
56 views

Odd syntax for ssh and bash to run command

I'm pretty new to shell/bash scripting and I'm writing a script on OSX to automate some rather tedious efforts. I'm trying to run a portion of my script on a remote host using ssh. There's a common ...
1
vote
2answers
25 views

Bash not sourcing ~/.bash_profile on os x

I just got this really wierd poblem. When I start bash, I get these two lines: -bash: fasd: kommandot finns inte -bash: brew: kommandot finns inte "kommandot finns inte" means command does not ...
1
vote
1answer
27 views

Have cron check if the bash script is executing

I have a bash script that users while do along with sleep to constantly monitor the connection state and take measures in case something goes wrong. The only thing that is not guarded is the execution ...
0
votes
1answer
29 views

How can I mount /home in a usb drive and keep the files?

I need to write a script that can mount /home in an USB drive at the boot and keep all the files in the USB drive after ejecting it. At every boot, if there is an USB drive plugged in, the script ...
4
votes
3answers
136 views

Log monitoring using shell script

I would like to monitor a log file for errors and then send an email to administrators. The log file contains data like below 11 Aug 02:30 Service1 restarted 11 Aug 05:35 Service1 restarted 11 Aug ...
0
votes
1answer
51 views

opening a terminal with a command on startup in debian

I have an application which is an object file (obtained from a c source code). When I run this application from the terminal it works fine. I want to run this application on system start up. Since ...
5
votes
2answers
45 views

Bash wrapper that will format the output of another program

Is there a wrapper or a method to force the output of another program (let's say 7zip) inside a bash script to be formatted in a given way, say, coloured or indented? Or even run in a separate small ...
0
votes
2answers
62 views

Display CPU cores usage in percentage without using top

I am using java to run a command on linux. Since top is an interactive command and need to press 1 to get the info of all the cpu(s) so I cannot use that. So I am using the following command to get ...
0
votes
0answers
32 views

find on bash script ignoring foldes with brackets [duplicate]

Strange issue here using bash, in the following script (this is a simplified version) the find command should bring all folders but it ignores some folders: /Home Made videos /Home made videos ...
4
votes
3answers
150 views

Get date of next Saturday from a given date

I want the date of the coming Saturday after a given date. For example, for $date1="30-AUG-2015", I want the result 05-SEP-2015. I have tried all the commands below with no success: samba@samba:~$ ...
0
votes
2answers
16 views

Assigning output of a Dynamic Performance View (v$asm_diskgroup) to a variable in Shell Script

I am trying to assign the output of select name from v$asm_diskgroup; to a variable in Shell . The script is failing because of special character '$' in the table name . Note : While i ...
-1
votes
3answers
86 views

Difference between two files

I have two files , say a & b. I want to compare both the files and get the differences in the third file along with the file name. Can anyone help me out with a simple command.
1
vote
2answers
64 views

Copy Single Value from a file to a variable and perform arithmetic over it? [duplicate]

Suppose we have a file like 'abc.txt' which has a single value 123456 and file 'xyz.txt' which also has a single value like 654321. I want to store these values form the file to some shell variable ...
0
votes
2answers
54 views

To add line numbers in every line using shell command?

My file, PSS-A (Primary A) PSS-B (Primary B) PSS-C (Primary C) PSS-D (Primary D) PSS-E (Primary E) PSS-F (Primary F) PSS-G (Primary G) PSS-H (Primary H) PSS-I (Primary I) SPARE ...
0
votes
0answers
20 views

How to enter username and password automatically in jrerun command?

jrerun is a command belongs to IBM Process Manager tool. This command will re-run the failed job. I want to create a script that re-runs automatically if it fails before 1 hour from start time. The ...
4
votes
1answer
55 views

Recursively grouping symlinks by original file

Pardon me, but I don't actually know where to begin with this - I will update if I get further. Sorry. Basically, I've got a list in a text file similar in structure to the following: ...
7
votes
3answers
435 views

awk does not end

I have the following code in a file named awktest1.awk: #!/bin/awk -f BEGIN{print "start"} {print $2, "\t", $5} END{print "end"} employee.txt where employee.txt contains the following data: 100 ...
-1
votes
2answers
100 views

How to remove a column or multiple columns from file using shell command?

My file, ARCHIVE B1_NAME B2_NAME B3_NAME ELEMENT INFO_NAM WERT PROCID -------- -------- -------- -------- -------- -------- ---- ------ ...
0
votes
2answers
59 views

Loop through * files using $1 in bash script

I am writing a script to act on files given to the script using the $1 variable. What is the best way to loop through these files. At the moment I have hard coded the script using something like for ...
0
votes
2answers
31 views

Copy file,create duplicates in different directory with predefined list of filenames

I have a file rock.mpg in the folder directory /folder1/folder2. I need to create multiple (340) duplicate copies of this file in a different directory say /folder1/folder2/folder3 but with different ...
1
vote
2answers
24 views

How can I list files by class/indicator (as in ls --classify) then by name?

ls --clasify append indicator (one of */=>@|) to entries. I would like to group the entries of the same class/indicator together. I can only find ls --group-directories-first for grouping the / ...
0
votes
1answer
44 views

Grep all strings from several binary files into one txt file

I've decided to play around dumping all process memory of couple utilities in order to find out, how much trace of sensitive info an attacker could theoretically obtain from app's memory. I've found ...
0
votes
0answers
21 views

To list only the file names in a present working directory using unix shell command [duplicate]

There are some links,directories and files in my path. I want to list only the file names eg. logfile1 redolog1 dumplog1 logfile2 lrwxrwxrwx spsy spec Jun 23 2343243 jpeg --> ~/home/s/jpegs ...
1
vote
2answers
39 views

A variable in Bash that contains quotation marks and spaces

I'm trying the following in a Bash script: MV_PARAMS='"foo 1" "foo 2"' mv $MV_PARAMS What I want to actually execute is: mv "foo 1" "foo 2" But it doesn't seem to work. trying this: mv ...
4
votes
1answer
60 views

How could a script know the path of the .desktop file that launched it?

How would a bash script know if it has been launched by a .desktop file, and how would it know the path of that launcher? Extra Points: How would I extract the "comment" field of that .desktop file - ...
1
vote
2answers
25 views

Checking that user dotfiles are not group or world writeable

I need to check whether user dot-files are not group or world writeable: The below command will list all the files: find /home/ -name "\.*" -perm /g+w,o+w Output: /home/system/.java ...
1
vote
1answer
38 views

nemo: Context Menu Action Triggering a Script that Forces the Selected Symbolic Link to be Relative

My goal is to be able to right-click a symbolic link in nemo, triggering a custom script that forces the link to be re-written as a relative path, should it happen to possess an absolute path upon the ...
3
votes
2answers
90 views

Memory usage of an infinitely looping shell script

So, I have a shell script for updating a MySQL database that looks something like this: #!/bin/sh mysql -h "localhost" -u "root" "-p********" "database" < "update.sql" sleep 5 sh $0 It sleeps ...
0
votes
0answers
25 views

Service failing to start during server boot

Facing some issue with jboss startup script for our QA box. The jboss service does not startup during reboot although the startup script is there. $chkconfig jboss --list jboss 0:off 1:off 2:on ...
0
votes
2answers
59 views

Bash script arguments not being passed to function? [closed]

I'm trying to pass the arguments when invoking a bash script to a function defined in that script. In my head this is trivial but in practice seems more difficult. Script is: #!/bin/bash function ...
1
vote
4answers
45 views

Linux replace last character in a csv file to new string

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. Data looks like this below: 124,Y,Y,Y,Y,S ...
4
votes
2answers
93 views

How to tail a log file by time?

Say my log file(log.txt) is something like 2014-01-01 22:30:30 something happened.... 2014-01-01 22:30:31 something happened.... 2014-01-01 22:30:41 something happened.... I want to tail this file ...
0
votes
0answers
20 views

Multiple here documents in a bash script to drop in and out of sudo is causing error “Sessions still open, not unmounting”

I'm attempting to write a setup script that I can run on multiple machines to run a bunch of installers (requires sudo) but also do things like pull down a git repo (I want to run that as the normal ...
0
votes
0answers
19 views

st terminal run block of code

I can run a command with a new terminal by typing st -e <command> How can I run a block of code this way, for instance: for i in {1..100}; do echo $i sleep 1 done I thought it would work ...
2
votes
6answers
269 views

How to Remove last comma of each line on csv using linux

I need to remove the last comma of each line. I have only one csv file, which looks like this: 98,N,N,N,N,S, 99,N,N,N,N,S, 101,Y,Y,Y,Y,S, I have the following script, but it is not working: for ...