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

learn more… | top users | synonyms (2)

0
votes
2answers
16 views

how to execute commands on remote server as different user

I am trying to connect to server B from server A using ssh and executing commands using some other user. However, when I try searching for a pattern in log file it says "cannot open log file" below is ...
1
vote
2answers
34 views

Bash script strange behavior with echo - printf in a file

I want to print part of the content of a .csv file in another file if there is a match with some condition: The csv content is like this abc test;ABCtest.it xyz test;XYZtest.com I read the content ...
1
vote
1answer
49 views

How can I skip empty files with sed?

I am using sed like this: sed -e 's/ *| */|/g' ${array_export_files[$loopcount]}>>$TEMPDIR/"export_file"_${testid}_${loopcount}_$$ under a while loop but problems come when the file is ...
0
votes
1answer
24 views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: 1) iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
1
vote
1answer
23 views

Match closest equal or preceding timestamp

I have a series of timestamps representing events, e.g.: 20150401_1120 // event a 20150401_1211 // event b And a series of logfiles, each representing a fixed period of time and timestamped ...
0
votes
1answer
15 views

Unix KSH or Bash Renaming of xlsx files tab [on hold]

I have a file of extension .xlsx which contains various sheets and the name of those sheets are getting displayed at bottom of file as Sheet01 Sheet02 Sheet03 Now I wanted to rename those sheets ...
0
votes
2answers
22 views

Dividing up columns and submitting the value as stdin into a seperate program within a script [on hold]

I currently have two programs written in C named "remove" and "calculate". When I call ./remove it removes some data from stdin. When I call ./calculate which takes in an argument and also data from ...
2
votes
2answers
36 views

Is it possible to change the PS1 periodically by a script in the background?

I just came across the PS1 variable (so I am far from being an expert). It is possible to change the prompt by simply changing this variables value, for instance: PS1="\h" hostname as Prompt PS1="\j" ...
0
votes
1answer
29 views

Want material to teach Unix basics [on hold]

HP-UX ** B.11.31 U ia64 ** unlimited-user license Hi, I have been working as a script (korn and bash)developer on Unix platforms for 3+ years. I have to train a team on Unix. And although I know a few ...
2
votes
1answer
21 views

cat to stderr while reading to end of file marker

Leaving aside the question of whether usage output should go to stderr or not, if you had to redirect the output of the cat command below to stderr, how would you do it? function usage { cat ...
0
votes
1answer
32 views

How to set path in cronscript

I am running a cronscript like: */45 * * * * /path/to/php /path/to/file.php it creates a file and put on home directory; But I want to create this file in my desired path like: */45 * * * * ...
1
vote
2answers
37 views

Script to hang up Asterisk channels

I am trying to create a script for Asterisk. We use a lot of channspy. Sometimes the channspy stays opened and didn't hangup even if the softphone is hangup (I don't understand why). So I thought of ...
0
votes
1answer
38 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
0
votes
1answer
33 views

List files with memory space older than 14 days

In shell scripting how to find 14 days older than files and directory in a account I need to list them with their memory space ex: 0 ./.vxz.tmp 658 ./.zshrc 6 ./dummy.txt 2.1K ./ss1s: 489K ...
0
votes
1answer
32 views

Moving multiple files from one folder to another and rename them [on hold]

I have a list of current file names and Original file names in a text file. The current name and the original name are seperated by a Tab or hypen. I want to move the file with the current file name ...
2
votes
2answers
38 views

grep with count of individual patterns

I have a file with MAC addresses (1/line with : as separator, sorted) and I need to find out how many times each of these MAC addresses appears in the file. I modified this: How to count occurrences ...
3
votes
1answer
22 views

Set the affinity of a process from a shell script as it is being launched

I have a script (.sh) where I launch applications like this #!/bin/sh ./application1 configuration1.cfg param1 param2 param3 & sleep 2 ./application2 configuration2.cfg param1 param2 param3 ...
0
votes
1answer
51 views

How can I translate in the CLI an English word into a German one?

I want to write a Script that picks a random English word from /usr/share/dict/words, translates it into German, display both of them for a certain amount of time and repeat the process. I only know ...
0
votes
0answers
63 views

sh: -c: line 1: syntax error near unexpected token `(' [on hold]

I am working with software that is based on Perl scripting and I have encountered a bash scripting error. So as I am not familiar with bash scripting, I don't know how I can solve this. sh: -c: line ...
1
vote
4answers
47 views

copying files to other location

I have multiple directories named such as: 15mar20a_00021sq_v01_00019en.frames 15mar20a_00021sq_v01_00020en.frames and so on... each contains 7 files having an extension of .raw. Examples of the ...
-3
votes
0answers
21 views

Daily mail with bash scripting [on hold]

We write daily base automated script for check data is available or not on some specific folder on that basis subject need to be change script trigger mail after complete data checks. Means if data is ...
0
votes
2answers
52 views

How to print an element from the corresponding immediate next column after searching the element in the current column?

I have thousands of lines as seen in the following list. file name = "textfile" 3 2 3 1 4 7 5 8 6 8 9 8 8 9 4 7 3 9 2 3 4 4 9 2 2 2 0 9 4 0 0 9 8 2 4 0 I have to search a particular element – ...
1
vote
2answers
42 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
1
vote
1answer
30 views

How to use convert command with bash to resize all images in a given directory?

I want to resize all PNG files in ~/somefolder/ whose filenames are NOT started with tn_ to 50% of its original size and rename the output file with a tn_ as its prefix and its original name. I know ...
0
votes
0answers
30 views

how to test login command in unix using shell script?

IN shell scripting I am using as : sudo login $user && echo 'yes' and expecting "yes" as output. But its not as per expectation. ****Actually my task is to automate "login" command to test in ...
4
votes
1answer
70 views

How to perform the watch command onto expression with pipes?

I learned today the wonderful shuf command: ls | shuf shows me a listing of the working direcotry, but thanks to shuf each time I execute this piped command expression with another order. So I ...
5
votes
1answer
324 views

How to copy a file several times into randomly choosen paths within the filesystem?

I have a filesystem and a special file foo. I would like the script to choose several times (5,10 or 100) random paths to folders within this filesystem and to copy the file foo into each of them. ...
2
votes
3answers
68 views

How to take variables from another Makefile in shell script

I want to use the variables from another Makefile under the directory ~/kernelbuild/linux-3.14.37 in my own shell script. Following is the variables that I need: VERSION = 3 PATCHLEVEL = 14 SUBLEVEL ...
1
vote
2answers
79 views

regular expression to extract information in shell script

I would to grep certain parts of some shell command output in the shell script: $ uname -r >> 3.14.37-1-lts Where I just need the 3.14.37. And also for the shell script variable VERSION that ...
0
votes
0answers
36 views

How do I realize a Shell Script that keeps track of how long the keyboard has not been used ?

Is it possible to write a script that counts the time between two pressed keys, so that one could put a script into the crontab that checks if the keyboard had not been for longer than a certain time ...
0
votes
1answer
42 views

Syntax Error: unexpected end of file — Bash script [on hold]

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 ...
3
votes
1answer
24 views

Moving sub-directory to new parent directory where the new directory name is incremented by 1

I am attempting to move a sub-directory from one parent directory to another for hundreds of instances, while changing the name of the sub-directory during the move. My directories are a set of ...
2
votes
4answers
84 views

Calling scripts from inside other scripts

I have a script which I call every 10 minutes with a cronjob: */10 * * * * ~/mydirectory/myscript.sh Now, inside ~/mydirectory there is also another script, let's say myotherscript.sh which I'd ...
0
votes
1answer
50 views

Why are my variables not reset to zero?

In the below loop, I try to reset the values of two variables (totalentries and totalusedbytes) to zero, but I can see from the results that it never happens. Thus each loop continues to add to the ...
-2
votes
3answers
35 views

Syntax error when trying to cut part of a variable

If I write a simple echo $i, I have no problem: it shows me the variable. But if I try do something with it $($i|cut -d"." -f1-3) then I get an error messages : -bash: /...file.backup: Permission ...
2
votes
4answers
55 views

Does it make a difference (e.g. performance-wise) if I execute a command from a bash script (vs the command line)?

Is there any difference between the following (e.g. performance-wise): $ make && cp bin/myexecutable inputfile.txt $workdir && cd $workdir $ <series of sed commands to modify ...
2
votes
2answers
66 views

Print file contents and delete the printed content* from the file

In Linux, from a bash shell, how can I print the contents of a file and remove the content I just printed content from the file? I have a program writing texts to a file repeatedly. On a Linux shell ...
2
votes
2answers
85 views

How to remove duplicate files using bash

I have a folder with duplicate (by md5sum (md5 on a Mac)) files, and I want to have a cron job scheduled to remove any found. However, I'm stuck on how to do this. What I have so far: md5 -r * | ...
-3
votes
0answers
33 views

Convert file pattern in Unix

I have a file with content as below 31/01/2014 1234 2234 4567 3321 ...n Need to write a shell script to convert the above file as below: DD_Date='31/01/2014' ...
1
vote
3answers
40 views

CSV Units Conversion

I've got a CSV file that looks like the following: miami,20,in lansing,2,cm austin,3,mm chicago,5,miles phoenix,2,feet The first field is the name, the next field is the numeric value and the third ...
1
vote
1answer
45 views

Write text on last line of document [duplicate]

If I have this document aaa bbb ccc And I want to add " ddd" on the last line. My document should look like this: aaa bbb ccc ddd How can I do this? If I prefer awk or sed but ...
0
votes
1answer
55 views

tar unused files then delete them

I have folder with subfolders and sessions logs. I need some commands or script to tar this folder without usage files and then delete it. I have this construction, but I'm not sure if this leave ...
2
votes
1answer
95 views

grom() keyword in bash throws unexpected '(' token

I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that ...
1
vote
1answer
56 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
1
vote
3answers
79 views

Find result used in if statement

How can I use the result of a find command in an if statement and compare with true or false? Something like this: if [ `find . -name test.txt -size 156c`="true" ]; then echo Found; fi This is ...
0
votes
1answer
39 views

User Input Bash Script

I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could ...
0
votes
2answers
41 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
1
vote
2answers
30 views

Read file remove spaces and store in array

I have a file with the following content: list: blue,none red,none orange,plot baseball , none university,none school,none desk,plot monitor,none earphone,none I need to read this file, ...
0
votes
0answers
33 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
0
votes
2answers
46 views

Adding 1 string to end of file, Even when ran multiple times to change MD5

I need to change the md5 of my files, Sometimes once, sometimes multiple times. A friend gave me this script to add a string to the end of the file but i think i may be adding it multiple times when i ...