Programming :: Scripting, Perl Or Bash; Run A Background Process, Get Pid?

Apr 1, 2010

pretty simple. how would you background a process from a script and get its process id at the same time?

View 6 Replies


ADVERTISEMENT

General :: Bash Scripting - Executes A Few Perl Scripts - Create A New Array And Take The Hostname

Apr 4, 2011

I'm writing a bash script that executes a few perl scripts. One of the perl scripts that I need to execute requires two arguments with it. The arguments are stored in a txt file, each line contains a hostname and its corresponding IP address separated by a ":" (colon), the txt file looks like this below:

[Code]...

I'm not sure if it's the best way to accomplish this but here it goes. In the bash file, let's call it getHosts.sh, I create an array and assign each line of the file to an element in that array. I then think I need to create a new array where I take the hostname (which is before the ":") separate it from its IP address and place the IP address on a new line just below the hostname (this way I can reference to it like $hostNames[$x] would be the hostname, and $hostNames[$x+1] would be its IP address). So the new array would now look like this below:

[Code]...

View 4 Replies View Related

Programming :: Compare Two Files Using Perl Or Shell Scripting?

Mar 8, 2010

I want to compare the following two tab-delimited .txt files (both were subsets of the original files) by comparing Columns 3 and 4 simultaneously. It is easy to compare C3 because both C3s are just numbers. But how to compare C4s?Basically, in File1, "G,G" = G in File2, "C,C" = C in File2, "A,A" = A in File2, "T,T"= T in File2.In File2, A/T in Column4 just equals "A,T" or "T,A" in Column4 of File1. C/T in Column4 just equals "C,T" or "T,C" in Column4 of File1, and etc.

File1:

C1C2 C3C4
ih509rs12345467244750"G,G"
ih499rs6049687244911"C,C"
ih508- 7244977"A,A"

[code]....

View 2 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Programming :: Perl Scripting: Search For Regular Expression Not Work?

Oct 13, 2010

I'm writing a Perl script to find an old key in a file and replace it with a new codefirst the program should find the old key in the input file. here is the way I used in my script. but it doesn't work.May you please let me know what is wrong and how I can correct it?the key is stored in the file in the following format:

PHP Code:
Key=("1234567" , someOtherVrable) 
I want 1234567

[code]...

View 1 Replies View Related

Programming :: Scripting The Email With Bash?

Jul 8, 2010

I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?

View 2 Replies View Related

Programming :: Bash Scripting: How To Keep Leading 0 On ' And '

Jan 27, 2010

I'm trying to put together a script that will quickly run through an archive directory of log files that are named by day of the month 01.gz, 02.gz, 03.gz.... 31.gz. The script uses gunzip -c | grep | wc to count up the total number of hourly occurrences of a filename and outputs the results to stdout.

The only snag I have left is the octal limit when it gets to 08 and 09. I've seen examples using perl and awk, but this script uses a number of nested for loops and if statements that I don't want to have to rewrite in a different syntax. I found that I can use num=10#08 to set that variable to a base 10 instead of a base 8, but then I lose the leading 0 again when it passes the number to the next filename variable.

View 8 Replies View Related

Debian Programming :: Bash Scripting For Jessie

Aug 25, 2015

You are probably using systemd (check it with ps --pid 1) and therefore /etc/init.d isn't considered for autostart. Here can you find some information about systemd and autostart [1]. As far as I know systemd isn't intended to start applications with systemd. I recommend you to use the autostart feature of your window manager or desktop environment or at least the .xinitrc.

[URL] ....

View 7 Replies View Related

Programming :: BASH Scripting - Creating A Map Tree?

May 7, 2011

looking to write a dependency map tree that creates a tree structure of object names . This tree will be written to a file and read back to create the tree structure of files . how to write this using bash ?

View 1 Replies View Related

Programming :: Bash Scripting: Menu From File?

May 29, 2011

I have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range

Code:
#!/bin/bash
p=`cat list.txt | awk '{print$1}'`

[code]....

View 2 Replies View Related

Programming :: Bash Scripting - Pointed In The Right Direction?

Jul 6, 2011

I've been using Ubuntu for about 6 months now, but haven't had a need to start scripting until just recently. I know programming basics, but that's about it.Anyway, I have a program that I would normally run in this manner (note that I didn't create a permanent alias because I've been moving the program around a lot):alias dx='python /path/to/dxProgram.py' dx A_input.dx B_input.dxSo, you see, program dx takes two input files, and 'A' must come before 'B'. I have a folder full of these types of files that I'd like to loop through with this program. They're named as follows:

0_A_input.dx
0_B_input.dx
1_A_input.dx

[code]....

View 6 Replies View Related

Programming :: Bash Scripting - Logging To The Virtual Account?

May 21, 2011

I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files). I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin. If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :

adashiu_at_virtual_machine_name >

after that user can start to use commands reserved only for user mode. Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him. changing prompt and separated commands for user and admin ?

View 8 Replies View Related

Programming :: Bash Scripting Arrays And Indirect Referencing

Feb 23, 2010

I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.

declare -a arr1
arr1=( $(/some/command) )

Supposing it will eventually (after executing the command) have element values as -

arr1[0]=1234
arr1[1]=5678
arr1[2]=7890

Now, I need to declare another set of arrays, one for each of the element values above - e.g.

declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890

And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -

arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"

arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"

I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.

View 7 Replies View Related

Programming :: Bash Scripting - Output As Multiple Files?

Jan 26, 2011

I have wrote a 1 line command that parses a file, locates the IP Address in the file and then trims the output the way I want it, and then sorts numerically and by uniqueness and then >> appends to output.txt

I can get all the IP's into 1 file "output.txt", but what I am really looking for is some type of way to create a text file, for each IP it finds labeled xxx.xxx.xxx.xxx.txt and also put that ip address into that file..

xxx.xxx.xxx.xxx = the ip address it finds

View 14 Replies View Related

Programming :: Bash Scripting With File Date Comparison?

Mar 23, 2011

I need to be able to compare a file date with system date and delete files older than 30 days.

the file name is basically
error_log.03222011

of course the extension is the date the file was created.

Oh and before i get hammered I looked everywhere but am unable to make sense of what I found.

View 3 Replies View Related

Programming :: BASH Scripting - Creating A Custom Service (CentOS)?

May 7, 2011

I am trying to create a custom service to manage a minecraft server what runs in a screen session (this is to allow easy console access as opposed to running it as a nohup background process). I am hitting two main issues with this script so far and wondering if anybody is able to shed some light on it, considering I am far from the greatest BASH scripter on Earth.

The issues are related to start and stop. the first issue with start is there is a command run "screen -dmS minecraft java -Xms1024M -Xmx1024M -jar /minecraft/minecraft.jar nogui" what doesn't appear to work, however when run from console (copy and pasted) this command seems to run perfectly. I am uncertain as to why this is not working within the script. Also if run from a script in /minecraft it also appears to work but in the minecraftd script I have created at /etc/init.d it does not work. I think the issue might be related to the location but am not certain on it, nor how to resolve it.

the second issue with stop is that it works sometimes but at other times it does not, overall it seems to work about 30~50% of the time. When it works it passes a couple of disconnection messages to the screen session and then gives the stop command (the command to gracefully terminate the minecraft server). It seems to work more often when using screen that I attach to the minecraft session while it is running but really not sure if this is an issue with my scripting or an issue with how I am passing things to screen.

The full code in /etc/init.d/minecraftd is below

Code:

#!/bin/bash
## Script Information
## Script Author: Berwick East

[code]....

View 9 Replies View Related

Programming :: BASH Scripting: Hide Plain Text Passwords

Jun 15, 2010

I was wondering if there is way to hide passwords in bash scripts. For example: I have to write a script to export a full ldap structure, and I'm using the ldapsearch -y passwordfile, where password file is a plain text file that contains the password. Is there a way to hide the password from that file?

I was thinking to remove the r attribute from the file and before the script is lunched to put the attribute back, but is not a good solution, the same with immutable attribute.

View 7 Replies View Related

Programming :: Bash Scripting...read A Value From A File Then Assign To Variable?

Feb 27, 2011

At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3

View 9 Replies View Related

Programming :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

View 13 Replies View Related

Programming :: Perl - Process Control As Different Users?

Jan 10, 2010

I need to control daemons like dhcp/bind from within a perl script. I could run the script as root to restart/stop/start the daemons however, this is not good for security.

What are the ways of controlling processes within perl as different users?

View 1 Replies View Related

Programming :: Bash Scripting Handling User Input Sections Automatically?

Jun 17, 2010

I have a system setup script for my Slackware installations that pulls all packages and source files from another machine and sets everything up to be identical between machines. The script works as expected but make it entirely unattended. How do I make the bash script deal with automatically selecting "Yes" for, for example "Install x(Yes/No): " when prompted by a make file?

View 3 Replies View Related

Programming :: Process Does Not Write To Disk While On Background

May 18, 2011

I am doing a program that reads data from a gps and some other devices and writes some files with all the information. When I run it normally it works fine, but if I run the program in the background (with the ampersand) files are not created until I bring it to foreground or close it. I am confused, the program should run the same way with and without the ampersand. (Could it be that the main process that creates all the threads does not create them when it is executed in background? It seems like if the program is stopped until I take it to the foreground).

View 4 Replies View Related

Programming :: Gracefully Exit A Background Process?

Jun 7, 2011

I am using a program that reads in data from a serial port and then sends that data out over a TCP connection. The problem I'm having is that the only way I know to exit the program is to do a 'kill PID', but doing this means the program doesn't go through the motions of closing the TCP connection properly so I have to wait some random period of time for the port to free itself or else when I try to start it back up it tells me that it can't bind to the specified port.The general structure of the program is as follows

Code:
int main(){
// initialize some stuff

[code]...

View 1 Replies View Related

Programming :: Bash Scripting To Programming?

Jul 13, 2011

i'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability

View 12 Replies View Related

Programming :: Bash Scripting - Display Real Name From Username Logged In + User Processes?

Jan 14, 2011

i am using putty to connect to the linux server and i am using nano as my text editor to write a bash script.

this is my script:

echo "Please enter your Username"
read userName
userName= grep $USER /etc/passwd | cut -d: -f5
echo "Welcome " $userName | cat >> output.txt

the problem i have is that when i enter my username, the output (my real name) does not display in the output.txt. instead it displays in putty. so when i run my script in putty it shows the message to enter username and after i enter my username my real name appears below it. i want it to show in the output.txt

View 1 Replies View Related

Programming :: Bash Scripting - Taking User Input And Adding It To A Particular Area Of A File?

Jan 12, 2010

in bash scripting...say I want to take the input from a user via a question...I would do this:

Quote:

#!/bin/bash

echo "How large do you want this partition to be in GB (enter only the number)?" read PART_SIZE echo "You want your partition to be $PART_SIZE GB" But I don't want to echo it back to the screen, I want to add it to the content of /etc/fstab. I have been mucking around with sed to find the tmpfs partition in /etc/fstab and add the partition size attribute (this is to use the onboard RAM as a volatile partition)...but am not having any luck...

The portion of /etc/fstab that uses /dev/shm for the tmpfs partition is:

tmpfs /dev/shm tmpfs defaults 0 0

So, if a user says "24" GB to the answer (from above), how do I get it to automatically add that value to the tmpfs partition line in /etc/fstab? So it would look like:

tmpfs /dev/shm tmpfs size=24g,defaults 0 0

I understand that I would also have to come up with a way to put "size=XXg", which I could do with a copied over generic file before this action...then the script would have to find "XX" and replace it with the user's figure...

View 7 Replies View Related

Programming :: Bash Scripting With Sudo / Password Prompt And Accepting User Input?

Jul 30, 2011

I'm creating a bash script to do some tasks for me. I would like the script to be run at a set time of everyday. My first question is if it is possible that if one of the commands in the script requires sudo, is there a way to get around it with out making sudo not require a password. Such as, is there a way to include the password in the script? If that is the case, I can always just set the file as read only by sudo. I've been looking for a way to do this, with no success. if I have a command that wants input, how do I give it to the program. For example, if I want to make a zip file that is encrypted, the command would go as:

Code:

zip -r example * -e

now how would I get the script to insert my wanted password.

View 14 Replies View Related

Programming :: STDIN, STDOUT, STDERROR Redirection For Scripting - Bash: Log.txt: No Such File Or Directory

Sep 7, 2010

I'm writing a script to execute bash commands in the PHP CLI. I would like to suppress errors from bash and write my own error message if an error occurs. So far I have this (assuming log.txt doesn't exist!):

Code:

tac log.txt 2>/dev/null

Which works as expected, tac kicks up an error but the error is suppressed, but when I use this:

Code:

tac < log.txt 2>/dev/null

I get:

Code:

bash: log.txt: No such file or directory

The tac error is suppressed but bash still gives me a dirty error.

View 2 Replies View Related

Programming :: Perl Behavior When Process Launched In `backticks` Crashes

May 11, 2011

I have a friend (really), who is the author of a Perl application that uses backticks to launch an external application. The process reads a largish set of data files, and printing largish amounts of data which is consumed by Perl. Very rarely, the external application crashes. When it does, the Perl script has been seen to hang, and the host CPU usage goes to 100%. The Perl script can be killed and the host recovers.

The question is whether this is predictable/expected behavior, and if it is, is there anything within Perl which can be used to defend against this behavior. I have already recommended the use of the open() form of reading from a child process, but I'm not sure whether that really accomplishes anything. My theory on the matter is that Perl ends up busy-waiting on the child's output, never receiving any EOF, and consuming all CPU. I cannot see how using open() changes that behavior. I am now interested in this problem so I can avoid causing similar behaviors in the future, and just because 'inquiring minds wish to know'.

EDIT: I suppose I should have added that this is on generic 32-bit Linux hosts; Perl 5.8.X

View 11 Replies View Related

Programming :: Bash And Perl - Script Adjustment

May 24, 2010

I wrote this script for bash & perl. If you run it in bash it should work. It changes title - (uuid) kernel - initrd ... to title - uuid UUID=the_uuid... kernel - initrd .... When I wrote it I replaced end of lines by . It's the second $block definition. But now I need to repair it, because I will work with the 1st $block definition. That is not to exclude end of lines, but leave it be untouched. Now when you escape the second $block definition, the code does not work. What I have to do to repair it working with multiline input data?

Code:
block="title Sata Mandriva
kernel (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c resume=UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798 splash=silent vga=788
initrd (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c)/boot/initrd.img"; .....

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved