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

learn more… | top users | synonyms (2)

3
votes
2answers
69 views

Syntax error: word unexpected on io redirection on file descriptor ≥10

I have the following shell script on debian 7: #!/bin/sh case "$IFACE" in lo) # The loopback interface does not count. # only run when some other interface comes up exit ...
2
votes
3answers
61 views

How to process a while-do loop and sort the iterated output

I'm very new at Bash Scripting so forgive my ignorance. I have a text file with last names that I am reading and processing line-by-line an average of three test scores. I need to output the lines ...
1
vote
1answer
57 views

C Shell detemined the file

I'm very new to C Shell. I'm trying to read a file from the command line, and determine whether it's a zip file, a .txt, a symbolic link, a pipe, or whatever ("unknown"). Then I'd like to execute a ...
3
votes
1answer
77 views

Mirroring stackexchange including external images

This script will create a mirror folder with all my activity pages saved for offline reading including all affected questions #!/bin/bash USERNAME=rubo77 MAXDEPTH=2 # increase this if you want to ...
2
votes
0answers
57 views

Copy folders at once

I want to copy a large number of folders at once not one by one. Is it correct to use the following code ? Is it helping to run the command cp for all the folders i at once? #!/bin/bash foreach i in ...
0
votes
2answers
74 views

cat STDIN won't work twice in script

I have a script that outputs various information and the text fields of an html form (method POST). When I attempt to cat <&0, it displays properly. However a few lines down, I try to cat ...
1
vote
1answer
36 views

For loop for curling on multiple pages with API's

I am trying to crawl a website for fetching pages using an API. When I issue the command cd desktop/mysite ; curl -O https://api.mysite.com/info?page=2 I get the data on the desktop. Then I wanted ...
1
vote
1answer
52 views

how do I remove ./ from the file name

How do I remove ./ from the file name ./script 1 when entering it as a command. I want to be able to enter the command just as script 1 for it to run?
4
votes
2answers
257 views

Script working on Mac but not Ubuntu

The script executes on a Mac machine and creates the output file, although on an Ubuntu machine it generates error message. Bash shell is used on both instances.: 1 - /var 2 - /etc : 1 : bad ...
-1
votes
1answer
31 views

SMTP log anonymize script

I have a SMTP log with records in the format below: 6,222.3.4.5,3040,100.2.3.4,25,UNKNOWN,0,1,……,9337bc-929a-34c0-29a8-b3a89c834b29 ,protocol,SMTP ,745663746,STATUS-COMPLETE ,VALID ...
0
votes
2answers
122 views

Constantly check if file is modified bash

I have a file called file1 I want in a script, whenever there is a change in it, do something, a beep sound actually. How do I do that ¿? Thank you in advance
1
vote
4answers
70 views

How to use regex in sed?

I need to revoke the sudo access to the user using sed in scripts. I want to comment the user only if the line contains /bin/su - root Let us consider the file as below, in which I have to comment ...
0
votes
1answer
47 views

Shell script equivelent to PHP $_POST

For example and learning purposes, I have a webpage that uses POST method to submit a text field. I have a server running script (bash) that I want to display what the "Query_string" is. I'm not ...
1
vote
1answer
125 views

How To Send Terminal Commands To Remote Server After Connecting Via putty? [closed]

In order to listing all batch files and finding the required file from a directory, I am using windows script to connect to the linux server. I can able to connect by passing necessary parameters but ...
2
votes
2answers
274 views

how to detect if command execute failed in shell?

I use Java to call a shell script in remote machine. I want to know if the shell execute failed. But I found that, checking the return code $? after the script is finished doesn't work. $? only ...
1
vote
1answer
97 views

Find the process which is taking maximum CPU usage if CPU usage is more than 60%?

I am trying to measure the cpu usage of my ubuntu machine and if the cpu usage is more than 60%, then I need to find out the process who has the highest cpu usage and then send out an email saying CPU ...
2
votes
2answers
62 views

Using a for loop to loop over multiple arrays in bash

Bash doesn't natively support two-dimensional arrays, but I would like to simulate one. As a minimal working example, suppose that I have two arrays, a0 and a1: a0=(1 2 3 4) a1=(5 6 7 8) I want to ...
0
votes
0answers
19 views

Print the page count within the PDFs in a directory to a output txt file [duplicate]

The need has been to identify the total page count of all the PDF files we have in a repository. For that, I was able to come up with the following script. However, I'm now stuck with this situation: ...
6
votes
8answers
732 views

How do I construct a list with numbers like this?

How do I construct a list like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Where I run command 15 or something. Or if I specify 100 it would make it with 100 numbers or 10000 and it would make it ...
0
votes
3answers
23 views

Open tunnel only during local command run [duplicate]

I have a script that needs a tunnel to a remote server. Something like this: ssh -fNL 8080:localhost:80 my_server How can I close the tunnel after my local script ends? The above example is just ...
2
votes
1answer
99 views

Leap seconds and date

I've just discovered that Unix time does not include the leap seconds. I think it's quite surprising because doing that, it is slowly diverging from UTC... but that's not the point of my question. ...
0
votes
4answers
281 views

keep the last file of every month and delete the rest

I have files like below. I want to keep SEP 30, OCT 30....files and delete the rest. Can you please help me with any script? -rw-r--r-- 1 nbswmcm advboprd 13463761 Sep 2 01:19 ...
0
votes
1answer
31 views

Loop in script on remote server doesn't work

#!bin/bash client=`cat temp.txt` ssh node2@192.168.1.190 'while read line; do mkdir -p /tmp/$line ; done <<< "$client"' cat temp.txt has 2 lines: nk124 nk124 Above is my script, it does ...
0
votes
1answer
60 views

Shell string escape for command arguments [duplicate]

I'm trying to create "/tmp/pwet/foo bar" with this: DIR="/tmp/pwet/foo bar" ARGS="-p ${DIR}" mkdir $ARGS For integration reasons, I have to keep the ARGS building in 2 steps: ARG = some_options + ...
1
vote
2answers
76 views

React to incoming files in a directory on HP-UX

How can I achieve this logic using a script: Monitor new incoming files in a directory. If files are not received in the directory for 3 hours or if the received file is empty then do something. ...
1
vote
5answers
78 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
5
votes
2answers
315 views

delete a line if same line exists in the previous line

I want to remove lines which exist already in the previous line from the command line in UNIX. I have the following data in a file. <xref ...
2
votes
6answers
91 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
1
vote
2answers
63 views

Add certain words to a file

I am using this code to read the line number 2 from files has the same name and included in folders (the name of those folders included in list.txt): #!/bin/bash in=/au/cl/tr/129/ inlist=/1/2/3 ...
-1
votes
2answers
107 views

reading from file using the command sed

I have a list of folders (the name of those folders mentioned in the file list.txt).I wanted to read the line 2 in all the files (the files in the folders has the same name) and print that line in a ...
2
votes
1answer
74 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
1
vote
0answers
86 views

Cannot add startup service to openWRT from init.d

I have openWrt installed on a TP-Link TL-WA901N/ND v3. I don't have luci package installed because I don't have enough space, so I can only do thing via cli. What I'm trying to achieve is to create a ...
1
vote
1answer
34 views

Cron Job Not working [closed]

I have been trying to create a cron job to execute a script located in ~/Documents/script.sh at midnight every night and every 8 hours after that. I have found a lot of material on this but for some ...
2
votes
3answers
70 views

Error while assigning current directory to a variable

#!/usr/bin/env bash if [ "$outDir" == "" ] then echo "$PWD" ,"We are here ", $outDir ," with " "$outDir" = "$PWD" echo "Yes" fi Output on terminal: ...
2
votes
2answers
94 views

How to capture the port number from this `lsof -F` output using awk (or something better)?

I've got output coming from lsof -F that looks like this: p7646 g7646 R8300 csocat u1000 Labe f3 au l tIPv4 G0x80002;0x0 d640391 o0t0 PTCP n*:51352 TST=LISTEN TQR=0 TQS=0 I am trying to capture the ...
2
votes
4answers
74 views

Merging Two Files with Difference only

I have two files. file1 contains text as follows: #This Data written by the platform Team id=kingDB file2 contains the text as follows: #This Data written by the platform Team id=kiteDB,mangoDB ...
1
vote
3answers
65 views

WMCTRL not working after starting xfce4-terminal

If I type these two commands in a terminal: xfce4-terminal --hide-menubar --hide-borders --hide-toolbars --title=dt wmctrl -r dt -e 0,10,10,720,720 I get the desired result (position and resize of ...
0
votes
1answer
61 views

Launch BASH script by clicking icon and preserve terminal icon

My problem is pretty simple, but I must admit, I don't know any elegant solution. I have a problem, that I often accidentally click different icon that I wanted. It's really very unpleasant, so I've ...
2
votes
1answer
57 views

How to run a program that has its own command line within a shell script program

I need to write a shell script to automatically run a set of files through an existing program ~1000 times. The program I'm trying to run them through is accessed through command line as follows, then ...
4
votes
3answers
313 views

Hide ouput of bash while running automated script.

I have a couple of scripts in my bash file, that should do certain tasks, say like ... #!bin/bash yum -y update service restart nginx yum install atop cat /var/log/somelog.log > ...
3
votes
7answers
227 views

get parts of string using shell script

I have one string as /ip/192.168.0.1/port/8080/ I want to get two separate variables which will contain port and IP like. 192.168.0.1 and 8080 as I know /ip/ and /port/ will be there always I ...
4
votes
4answers
369 views

Text files containing their own name

I need to find in certain directory and all its' subdirectories all text files that contain their own name. How do I do this? (preferably without awk command)
2
votes
1answer
31 views

Help me understand what sort is doing here

This is a followup to this question : What does sort -n do with non numeric values? Here is my input: 1-----*** R----**** 1---***** And I run: sort -k 1.2,1.9n input.txt > output.txt Here is ...
4
votes
3answers
240 views

Add text with echo but start with new line if file not empty

I'm trying to create next script echo "#!/bin/sh" >/script echo "del x.txt" >>/script witch is ok if /script file is empty, if not - will append first line to last text #!/bin/sh del ...
0
votes
0answers
25 views

What does sort -n do with non numeric values? [duplicate]

I'm translating an old korne shell script that uses sort. The exact command is: sort -k 1.2,1.9n -k 1.10 -k 1.18,1.19 $LOAD_FILE > $SORTED_FILE The input file has some lines where the values in ...
0
votes
0answers
21 views

Script GUI problem

I have an application in C++ which show a ipcamera video when I send it a value by ethernet. I want that the application start at boot in automatic way. This is my script: #!/bin/sh ...
3
votes
3answers
107 views

Count nul delimited items in file

I have a shell script which uses find -print0 to save a list of files to be processed into a temporary file. As part of the logging I'd like to output the number of files found, and so I need a way ...
-1
votes
1answer
37 views

I get "syntax error near unexpected token 'else' for the following script [closed]

if ! [ $result1 -eq $SUCCESS ]; then # failed to get the status from 1st ssd try with the 2nd ssd, to identify the primary and secondary ...
1
vote
0answers
44 views

Need a script to send an email when an input has not changed for more that 30 minutes

I need a linux scrip that will send an sms when there is an input change and it has not gone to the initial state after 30 minutes, I have the following so far, but, I am sure there are few things ...
3
votes
3answers
319 views

Split the lines of a text file into separate files

I have a text file that looks something like this: foo bar zip rar tar I need to use a bash script on OSX to make a new text file after every new line like this: cat text1.txt foo cat text2.txt ...