A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (2)

1
vote
1answer
31 views

VBox on headless server: install linux without RDP

I have script to setup headless machine on remote headless server, connected by ssh. It will create machine, attaches disk and archiso, and launches installation. Also, I have script to setup ...
12
votes
4answers
671 views

How can I propagate my SSH pub key to a list of servers without having to type my password in over and over?

I was recently given username/password access to a list of servers and want to propagate my SSH public key to these servers, so that I can login more easily. So that it's clear: There is not any ...
8
votes
3answers
10k views

What is IFS in context of for looping?

I'm learning bash scripting right now. I was reading this thread: How to loop over the lines of a file? What is IFS? With for and IFS:
0
votes
0answers
17 views

Script requesting information upon boot

The idea is to create a script that runs as root upon boot (either before a potential X or GDM starts or after). The challenge is that this script needs input from "the one at the keyboard" - without ...
74
votes
6answers
45k views

Allow setuid on shell scripts

The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor: > cat setuid-test.c #include <stdio.h> #include <unistd.h> int ...
7
votes
5answers
671 views

Modify a file without creating another file

Is there a way to modify a file without writing the contents to another file, without sed and awk? For example: $ cat test.txt aaa aaa bbb ccc ddd Replacing using sed with -i option, sed -i ...
0
votes
2answers
54 views

export PATH permanently [duplicate]

I have exported the PATH but once I switch to a different terminal or reboot Debian, $PATH is reset. Here are the steps I take: ~$ vim scripts.sh #!/bin/bash echo "Hello" I save it as mybash.sh ...
2
votes
2answers
577 views

securely automating a script which requires a key to do its task

I have a script that downloads bank transactions to store in a database. To get these transactions requires a password for each account. The database is encrypted and requires a key to access it. All ...
-2
votes
0answers
29 views

Find HTML tag and add it to text editor with script [closed]

Is there a way to open a website find a specific HTML tag and get inner text (or inner HTML) and paste it to text editor or text file. I'm new to Linux.
2
votes
2answers
4k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
1
vote
2answers
1k views

How to detect the command interpreter from within a shell script? [duplicate]

Possible Duplicate: How to test what shell I am using in a terminal? I want to detect which interpreter a shell script is using. For example the following script: #!/bin/bash ...
4
votes
5answers
5k views

Javascript to HTML converter?

Take for example this snippet of code on a web page. <html><body> <script language="javascript"> document.write("The cat"); document.write(" sat on the mat"); </script> ...
1
vote
1answer
34 views

Shell read script for sftp

I have this working: % cat read.sh !/bin/sh file=list.txt while read line do echo "$line" cut -d' ' -f27 | sed -n '$p' > file2 done < "$file" % cat list.txt sftp> #!/bin/sh sftp> ...
0
votes
2answers
62 views

Cron job which runs every 5 seconds

I need to create an cron job with the following functionality: The job should go to a particular directory and touch one file every 5 seconds. It should run for only 1 minute. The logic is to ...
1
vote
3answers
50 views

Remove special pattern ^M from script which got appended after FTP from windows to Unix

I send a windows file using FTP to an unix system and got appended ^M wherever a new line was intended, and I just want to remove them. One method which I can opt is to run dos2unix command. Can ...
1
vote
0answers
53 views

How to set Ruby GEM_HOME and GEM_PATH

I'm a NOVICE user of Linux and using Linux mint 17.1 I've reinstalled Linux mint 20 time in last 3 days for that issue but could not fix it I'm trying to install ruby on rails using rvm what ...
0
votes
1answer
33 views

Take output field data string into variable

I want to grep for some specific lines from a log file, and then capture a specific part of that output in a variable and use it in other commands. The grep command I have is the following, where $1 ...
1
vote
0answers
34 views

What's in your script Swiss Army knife? [closed]

I've been using Linux pretty heavily that past few months and I want to up my game. But so far my scripts have been focused on speeding up my development time. I'm looking for scripts that will just ...
1
vote
2answers
1k views

How to run java service as a non-root user on CentOs 6

I have a script that starts a Java application as a service on CentOS 6: #!/bin/sh # chkconfig: - 80 20 SERVICE_NAME=cn4server PATH_TO_JAR=/usr/local/share/myserver/cn4server.jar ...
4
votes
2answers
87 views

Checking if a command is a built-in in ksh

How can I check if a command is a built-in command for ksh? In tcsh you can use where; in zsh and bash you can use type -a; and in some modern versions of ksh you can use whence -av. What I want to ...
2
votes
2answers
520 views

Import single rows from SQLite to MySQL?

I need to do some kind of incremental import again and again from a SQLite 3 database to a MySQL database. Column names are the same in both databases. Is there a good way to do this by a script ...
1
vote
3answers
187 views

How can I run a program as a root user when my Ubuntu 15.04 machine starts up?

On Ubuntu 15.04 I have this file: /usr/local/bin/myscript (it's a script I made). If I run this command under my account, it will do what I need it to do as a root user: sudo /usr/local/bin/myscript ...
2
votes
2answers
527 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
6
votes
4answers
21k views

Storing output of command in shell variable

I have an operation using cut that I would like to assign result to a variable var4=echo ztemp.xml |cut -f1 -d '.' I get the error: ztemp.xml is not a command The value of var4 never gets ...
7
votes
6answers
6k views

Extracting nested zip files

I have numerous zip archives, each of which contains a number of zip archives. What is the best way to recursively extract all files contained within this zip archive and its child zip archives, that ...
1
vote
2answers
54 views

Pipe to my own script

I've recently noticed this message from grep "grep: warning: GREP_OPTIONS is deprecated; please use an alias or script" I receive this warning because --color=always is defined in my .bashrc file. ...
-7
votes
0answers
37 views

UNIX script to display the filename [duplicate]

How to answer the below interview question: With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename
3
votes
1answer
38 views

Solaris: PKG - Script To Verify All Packages Except for a Few

I'm trying to verify the all packages except for a pre-defined list of packages that I know are going to fail for known reasons. This script is going to be run on all Solaris systems within our ...
17
votes
5answers
27k views

File extensions for unix shell scripts

On wikipedia, the article for .sh says: For the .sh file extension type, see Bourne shell. How about other unix shells? I know that the shebang is used inside the file to indicate an ...
2
votes
1answer
29 views

Scripteable GPT partitions using parted

I am partitioning eMMC using following commands in the script, parted /dev/mmcblk0 --script mklabel gpt parted /dev/mmcblk0 --script mkpart primary ext4 32MB 132MB parted /dev/mmcblk0 --script mkpart ...
9
votes
7answers
970 views

How to merge text of alphabetic lines with the numeric lines in shell?

I Have a file that has text like this: AAAA BBBB CCCC DDDD 1234 5678 9012 3456 EEEE 7890 etc... And i want to match up the Alphabetic lines with the Numeric lines so they are like this: ...
0
votes
1answer
71 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
-1
votes
2answers
32 views

Extracting certain data within a script output file

We have a script that runs several commands and rolls up all the output and inserts in into a log file. One of the commands it runs is "netstat -anp". I'd like to be able to search this file for all ...
0
votes
1answer
1k views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
0
votes
3answers
72 views

Remove lines in a shell script

I have this file: # more file.txt 2c2 lns-ld-wall-01-t2 old:261,260 4c4 Prive_ORANGE old:258,259 I need to remove all lines like this one 2c2 and this one 4c4. How can I do in a shell script?
1
vote
3answers
62 views

Difference between sh -x and ./ for script execution

So I have a simple shell script. What is the difference between the two commands in execution? Is there a preferred way? $sh -x foobar.sh OR $ ./foobar.sh I found the script executed slower when ...
2
votes
3answers
4k views

Awk printf number in width and round it up

I need to printf a number out, but with given width and rounded (with awk!) %10s I have this and somehow I need to connect the %d but everything I do, ends up with too much parametres for awk ...
46
votes
9answers
62k views

Looping through files with spaces in the names?

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff ...
4
votes
3answers
855 views

Why read works if stdin is redirected to fd4?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 It redirects fd0 to fd4, and "/etc/XX/cfg" to fd0. So why does read still work, shouldn't that ...
10
votes
9answers
24k views

Automatically run commands over SSH on many servers

There is a list of IP addresses in a .txt file, ex.: 1.1.1.1 2.2.2.2 3.3.3.3 Behind every IP address there is a server, and on every server there is an sshd running on port 22. Not every server is ...
0
votes
1answer
23 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
6
votes
1answer
628 views

Can capabilities be used in scripts without setcap'ing the interpreter binary?

Right now I'm using cap_net_bind_service MY_USERNAME in /etc/security/capability.conf. Now I just need to set cap_net_bind_service+i on the interpreter of my favouite scripting language to be able to ...
0
votes
1answer
1k views

How to execute grep in tcl for getting XYZ-123 type pattern

How can I execute this grep command in TCL? grep '[A-Z][A-Z][A-Z]\-[0-9][0-9][0-9]' file1 > file2
-2
votes
2answers
68 views

Parsing a flat file using shell script

I have a file like in following format User:blala Pass:blala IP:***.***.**.** I tried with IFS but it is not working input="/path/to/your/input/file.cvs" while IFS=',' read -r f1 f2 f3 f4 f5 f6 ...
2
votes
1answer
35 views

Shell Scripting: Deleting or moving files from one directory that match filenames from another directory

I have a very specific and odd problem to solve. I'm working as a research assistant and I've been producing a ton of figures. In one directory, I dump .pngs to view casually (limited space here) and ...
1
vote
2answers
71 views

Capture errors in a SFTP script

I have a sub sh file which puts receives an input of local directory and path to the remote directory and sends the file to the remote directory. If the remote path is invalid the error cannot be ...
-1
votes
0answers
7 views

rpm package not updating as I update the spec file

I have some statement the %post section of my rpm spec file of the form echo "printing A" I updated the spec file to make it "printing B" but the new rpms I'm creating still echo "printng A" What ...
11
votes
3answers
6k views

How to “send” variable to sub-shell?

I run the following script: VAR="Test" sh -c 'echo "Hello $VAR"' But I get : # ./test.sh Hello How can I "send" the variable VAR of my script to the shell created with sh -c?
0
votes
1answer
24 views

How to execute several lines into a .txt

I am using SSH; In a folder I have the next files: -rwxrwxr-x 1 german german 48 Apr 29 10:45 prueba.txt -rwxrwxr-x 1 german german 23 Apr 29 10:43 script1.sh -rwxrwxr-x 1 german german 23 Apr ...
0
votes
1answer
41 views

Script for update

I need your help in a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need ...