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

learn more… | top users | synonyms (2)

2
votes
3answers
97 views

How to get cpu usage for every core with a bash script

I'm writing a bash script to print system stats to my dwm status bar using xsetroot. Everything works as expected. What I'm currently missing is an easy way that just uses standard *nix tools to give ...
0
votes
2answers
29 views

Using sed with herestring (<<<) and read -a

I use sed with <<< and read to assign all words in a string to variables. What I do is: read -a A0 <<< $(sed '2q;d' /proc/stat) Hence, sed reads the second line of the file file ...
2
votes
1answer
30 views

Storing whitespace in a shell script variable

I need to store specific number of spaces in a variable. I have tried this: i=0 result="" space() { n=$1 i=0 while [[ "$i" != $n ]] do result="$result " ((i+=1)) ...
-2
votes
1answer
25 views

how to pass enter character to other shell script [on hold]

One script needs enter key to proceed. Other file should send the key. I will run the command like below: sh scriptfile < file
0
votes
2answers
23 views

Searching out a pattern from Logs

The format of the logs is in this manner: Junk Junk Junk : Junk Junk Junk:IP/Port Junk Junk I want to search using the IP and the output should be only the IP/Port part of each line in that log ...
0
votes
1answer
32 views

How to start several jobs in different screen sessions in a Bash-script?

The programm I want use can be started via ./myprogram < input_part1.txt > output_part1.txt How can I start four jobs of myporgram in a BASH-script where each job runs in a separate ...
1
vote
1answer
29 views

How to ensure a bash script is executable via web without being in /cgi-bin directory?

My document root is /0/ i do not have any cgi-bin directories. this is my virtual host with apache: Listen *:80 DirectoryIndex 1 <VirtualHost *:80> DocumentRoot /0 ServerName domain.tld ...
2
votes
1answer
98 views

How to print a bash variable that has an array as value

I wrote a script for my dwm statusbar. One part of it is finding the current cpu usage for every single core on my system. I figured out a way myself but I would need some help fixing a bug in this. ...
1
vote
1answer
23 views

Global variable for every script

I want to declare a variable in such way that every script can access and alter its value. I have written a script that set the value of a variable called flag on exit and I am using a crontab entry ...
0
votes
3answers
607 views

compare two files based on a column and print it

I have two big files of 400,000 lines. I want to compare the column 1 of the second file with column 1 of first file recursively. If they match I would like to print the whole line. It is a sorted ...
0
votes
0answers
23 views

Zsh script cannot find screens

I have created a zsh script launching many screens in detached mode with particular names and running particular processes in them in order to automate some data analysis in high energy physics. ...
0
votes
1answer
22 views

Zsh script how to concatanate array elements with string

I have written a zsh script to automize an analysis in high energy physics and now I would like to use an element of the one of the defined array some string and another element of some another array ...
1
vote
1answer
111 views

How do I download PDFs from PubMed, given their IDs?

I have PubMed IDs for files I need to download from the PubMed site in .pdf format. I tried this script: #!/usr/bin/env bash Link="http://www.ncbi.nlm.nih.gov/pubmed/" ID=(10021369 ...
1
vote
1answer
34 views

How to extract values from a file using pattern(s) from a column in another file, and insert such values as a new column to the latter?

I sample "winning" sets of 60 game cards such as this one and extract the card names and count and format it for use with some software. The output format is: ...
3
votes
1answer
72 views

Tokenize string from $REPLY in bash script

This is my first post, and I have no idea how I managed anything before StackExchage, Google, Wiki, GNU, Internet, the list goes on :) I am trying to find a way to construct a SQL database generator ...
1
vote
1answer
202 views

What does this `cat` statement do?

I'm new to Linux and trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to ...
1
vote
2answers
38 views

Search for a string in the output of a command

I'm stuck with a simple script. I want to run tracepath on multiple address and to find if some IP is contained in the output of the tracepath. For now I have the following: if tracepath -n ...
10
votes
6answers
1k views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
2
votes
1answer
412 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
1
vote
3answers
47 views

Bash script in ( set -x ) mode does not display what “cat” command does. ( contents of it )

in this bash script.. it simply shows.. +cat as it runs. #!/bin/bash set -x cat > /test << "EOF" a b c d EOF but i rather show everything that it does . including the a b c d ...
2
votes
2answers
32 views

Sed find and replace with slashes

I am having trouble using sed find/replace with slashes in the find parameter. Sample contents of test.sh str=$(sed -n '/^user:/p' /tmp/shadowtest) # find "user:" line in /etc/shadowtest ...
0
votes
1answer
41 views

Running shell script on cluster in parralel

I thought dsh(Distributed Shel) will be a good option but when i ran my shell script across my nodes, I didnt get expected output, dsh -aM -c bash /home/cloudera/bash_script.sh server2@x.x.x.110: ...
3
votes
1answer
79 views

Login automatically as root

I am working with a board and when it finishes the boot, appears the login. What I want to do is login as root but automatically. I mean I want to do that when boot is finish, I can see the prompt, ...
1
vote
1answer
677 views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
9
votes
6answers
1k views

Detect init system using the shell

This may have more to do with detecting operating systems, but I specifically need the init system currently in use on the system. Fedora 15 now uses systemd, Ubuntu uses Upstart, while others use ...
2
votes
2answers
2k views

Get path of current script when executed through a symlink

I have a utility consisting of a couple directories with some bash scripts and supporting files that will be deployed to several machines possibly in a different directory on each machine. The ...
0
votes
0answers
33 views

Bash script for opening screens and compiling the same file

I have written a bash script to initiate separate screen sessions and run a command in each of them that compiles the same C++ source file in ROOT (an object-oriented data analysis framework ...
1
vote
2answers
29 views

Livesearch with first 10 matches as preview for zsh-history?

I have seen a history-livesearch with a preview, that shows the 10 first matches in the history in a list below the BUFFER-line, which is updated on every keystroke, and acts like the standard ctrl+r ...
1
vote
1answer
27 views

TCL script try catch

I have a TCL script that sets a number of variables and reads several files. The last file it reads may contain sensitive information, so I need to make sure this file gets deleted even if an error ...
0
votes
0answers
26 views

get time of file in inotifywait tool

for this script: inotifywait -m /path -e create -e moved_to | while read path action file; do echo "The file '$file' appeared in directory '$path' via '$action'" # do something with the ...
0
votes
0answers
8 views

How to use scanner drivers api in Linux shell script

Usually when scanning any page using Canon DR- 2050C scanner in windows it rotates vertical text paged to horizontal automatically for the easy reading of the user. In Linux we are manually scanning ...
1
vote
4answers
163 views

How can the following script be explained?

Code: #!/bin/csh if ( A$1 == A ) then echo "" echo "LIST <name>" echo "" exit endif .............. Ok this is a sample from a bigger script I got. The scripts starts with ...
0
votes
2answers
68 views

Intro to shell scripts with basic application: how do I set my computer to make an archive of a particular folder every day?

I've got a situation where I need to give some people access to my dropbox folder. Already so far they have deleted huge folders full of important data. Their computer skills could use a bit of ...
0
votes
0answers
23 views

Run Xserver as root

I am working with an ARMStone a9 board which has iMX6 linux kernel. I am doing an embedded application in which I have to show a video from Ipcamera. The thing is that I attached the screen to my ...
-2
votes
2answers
45 views

Unix AWK command with multiple field seperators [closed]

I faced a problem with awk where my field separator has multiple characters. I have found the solution but I am unable to understand the script. awk 'BEGIN{FS="[char1][char2][char3]+";} This is how ...
4
votes
1answer
55 views

Bash script for scp interpreting tilde (~) too soon

So, I just started a new C++ class that requires me to program in a Linux environment. I don't have Linux installed on my machine, but I do have OS X and I can ssh into a linux machine in the lab at ...
3
votes
2answers
72 views

Loop in WildCard as Input of Script

I want to use my script on many files sometimes. I used this for the purpose: for etminput in $1 do #process done But this just gives the first input. How can I do the process on every ...
1
vote
2answers
18 views

Querying a remote POP3 Mail server using BASH

I'd like to connect to our mail server via POP3, look for a certain pass phrase in the subject and if found then run a script. How can I achieve this with BASH other than awkwardly scripting Telnet? ...
2
votes
0answers
13 views

unbuffer/expect swallows the rcode when its child is signaled

unbuffer is able to pass along the return code of a process under normal circumstance, but if the process you are unbuffering is killed, for instance with a segfault, I see $? as 0 while I expect 139. ...
0
votes
1answer
41 views

Is there a way to create a new file and insert text into this file all with bash? [closed]

I need to change and create several configuration files for some kiosks at work, is there a way to do this with a single bash script? I've heard about SED but the documentation is confusing, could ...
1
vote
1answer
497 views

Command/scripts to check the Reverse DNS Lookup time

I am working on a project in which one master communicates with numbers of slaves. For that it has to make connection with hosts in network. But sometimes it hangs. I think that the reason behind is ...
-4
votes
1answer
41 views

unix (batch file ) [closed]

Create one unix script, where a)Take name of file as input from user and create file with same name. b)in file write 10 lines of text and save it. c)search a string given by user, search that ...
0
votes
1answer
17 views

Header about MIME email

Morning, can some body help me about MIME email? I want to send HTML email like this: MIME-Version: 1.0 Content-type: multipart/alternative; boundary=lazuardi --lazuardi After that email. I have ...
2
votes
2answers
76 views

find file, copy but with different name

I have files with random numbers in /home/user/files folder (every 4 days I have new ones). for example: john20 john25 john40 tom12 tom32 simon2 simon8 simon53 I want to take only last modified ...
5
votes
1answer
1k views

Global /etc/profile setenv or export overwriting user settings in .profile

I need to call a modified version of a program in /home/user_name/bin rather than the (older) version in /opt/program_name/current on a CentOS 5.3 cluster. The program creates a tcsh script using ...
0
votes
0answers
31 views

How to remove files except a list with names files [duplicate]

I need delete some .desktop files in various directories and a text file with a list of file names. I want to delete all these .desktop files except for those listed in my text file). Example $ ls ...
0
votes
2answers
43 views

How do I validate a settings(ini) file for the values expected using bash?

After I check if the ini file exists where it is expected to be, which I've learned how to do, I would like to check the file for proper formatting. I'd like to validate any number of "site" entries ...
1
vote
2answers
92 views

Editing INI-like files with a script

I'm writing a script to automate setting up Puppet agent configuration files in Docker. Basically, I need to ensure that the following section is in /etc/puppet/puppet.conf: [agent] ...
0
votes
0answers
22 views

startx & screen goes off [closed]

I am working with graphical in a Linux linaro in a embedded system, and I use the startx & command for run it. My problem is that after 10 minutes more or less, my screen is goes off. I guess ...
1
vote
0answers
22 views

Run startx & automatically embedded syste,

I am working with a board in which I run my application which use th graphical mode. Everything works perfect. I start the graphical mode like this: startx & and then I run my application like ...