Sponsored Content
Top Forums Shell Programming and Scripting Perl - save results to output file. Post 302495669 by fpmurphy on Thursday 10th of February 2011 09:35:34 PM
Old 02-10-2011
Code:
use strict;
use warnings;

my $filepath = "ip.txt";
my $outfile  = "output.txt";

open (HOSTLIST, "$filepath") || die "ERROR: opening $filepath\n";
my @hosts = <HOSTLIST>;
close HOSTLIST;

open (OUTFILE, ">> $outfile") || die "ERROR: opening $outfile\n";

foreach my $host(@hosts)
{
   my $results = `nslookup $host`;
   chomp ($host);
   print OUTFILE "Results for $host:\n";
   print OUTFILE "$results\n\n";
}

close OUTFILE;

 

9 More Discussions You Might Find Interesting

1. Solaris

terminal output - save to file?

I have a window open on my ultra 10 - a terminal window connecting to a server. Is there any way I can log all output to this window to a log file on my ultra 10 ? (2 Replies)
Discussion started by: frustrated1
2 Replies

2. Shell Programming and Scripting

let curl output to stdout AND save to a file

hello hackers. i have a curl process running as cgi directly pushing stdout to the client. but i want to additionally save that stream to a file at the same time. any directions madly welcome. thanks in advance (3 Replies)
Discussion started by: scarfake
3 Replies

3. Shell Programming and Scripting

Save cURL verbose output to file or do it like browser "save as.."

hi there ! i have exactly the same problem like this guy here https://www.unix.com/shell-programming-scripting/127668-getting-curl-output-verbose-file.html i am not able to save the curl verbose output.. the sollution in this thread (redirecting stderr to a file) does not work for me.... (0 Replies)
Discussion started by: crabmeat
0 Replies

4. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

5. Shell Programming and Scripting

PERL Scripting: Diff 2 files and save output to file3

Hi, I need to create a script to compare 2 files and store the output in a 3rd file. This is how I do manually, but since I need to do this for about 150 files every week, I am trying to automate it using perl. diff -u file1 file2 > file3.patch For my script, - I have 2 files... (4 Replies)
Discussion started by: script2010
4 Replies

6. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

7. Shell Programming and Scripting

Save output to file - inside a script ?

I'm using the following script to check cisco router health and I'd like to save output to a file, vty_runcmd.sh > /check/check-cisco-health script works and output is saved to a file. However using it in crontab file is created but output is not printed inside it. In crontab, */5 * * * *... (4 Replies)
Discussion started by: marmellata
4 Replies

8. Shell Programming and Scripting

Save output into file bash scripting

Hi there. i have created a program that in the end it will give output like this 1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 .............. 17 i wonder how to save the output into a single string and into a file. i.e 1 10 11 12 9 2 3 8 13 14 7 4 5 6 15 17 (in this order,... (3 Replies)
Discussion started by: shdin271
3 Replies

9. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies
NETSELECT-APT(1)					      General Commands Manual						  NETSELECT-APT(1)

NAME
netselect-apt - create sources.list for the fastest Debian mirrors SYNOPSIS
netselect-apt [OPTIONS] [stable|testing|unstable|experimental|release_codename|sid] DESCRIPTION
netselect-apt automatically creates a sources.list file for using with apt for the specified distribution by downloading the list of Debian mirrors using wget choosing the fastest servers using netselect, and testing the valid servers using curl (if available). The output file is written to OUTFILE. The list of fastest servers is determined by checking through netselect, which servers responder faster to ICMP queries. In order to deter- mine if the servers are valid a connectiong using the specificied protocol (HTTP or FTP) is done using curl. If netselect is not installed setuid, then netselect-apt needs to run as an administrator user (i.e. root). This is only required because the network probes done by netselect requires these permissions. No changes are done to the system. If -i INFILE is passed netselect-apt uses that rather than downloading another copy to a temporary file. The file will be downloaded from http://www.debian.org/mirror/mirrors_full OPTIONS
stable|testing|unstable|experimental|release_codename|sid Specify which distribution of Debian to use. By default stable is used. -a, --arch ARCH Use mirrors containing ARCH. By default the architecture of the current machine is used as reported by dpkg -s, --sources While generating OUTFILE include also deb-src lines to use with ``apt-get source'' to obtain Debian source packages. -i, --infile INFILE Use INFILE instead of downloading the mirror list to a temporary file. The file must be in the same format as mirrors_full. -o, --outfile OUTFILE Use OUTFILE instead of sources.list. -n, --nonfree Include also non-free section while generating OUTFILE. -f, --ftp Use FTP mirrors instead of HTTP and generate OUTFILE accordingly. -O OPTIONS The OPTIONS provided are added, verbatim, to netselect when it is run. Here you can provide a (quoted) list of options for netse- lect. -t, --tests hosts Make a short list with the number of hosts provided and use that list to test for mirror validity. By default 10 hosts are tested. -c, --country COUNTRY Only test the sites found under the country COUNTRY (the value can either be an ISO-3166 value or the full name of the language, in English). When this value is set the mirror list or the INFILE will be filtered and only the sites that are listed under the given country will be tested. Note that restricting the search might not give the best results, as the "fastest" mirror might not even be in the same country as the system the program is running in. ENVIRONMENT
WANT_SOURCES setting this to 1 is equivalent to --sources WANT_NONFREE setting this to 1 is equivalent to --nonfree LIMITATIONS
netselect-apt is unable to work with restricted environments in which network filtering is implemented as it relies on netselect being able to find a suitable mirror. To do this, the system where the script is run needs to have network visibility of the mirrors, as it will probe them using ICMP probes. netselect-apt is also unable to work in environments where HTTP or FTP network connections have to be done through a proxy host, as it relies on being able to test the validity of the remote mirrors doing direct network connections to them. netselect-apt will not check if the mirror it suggests as the "fastest" mirror is either valid or up-to-date. It is recommended that users that use this tool also validate that the mirrors suggested are official mirrors and are also current. SEE ALSO
netselect(1), wget(1), curl(1), apt(8), sources.list(5). For Debian GNU/Linux it is recommended that users review the official mirror list at http://www.debian.org/mirror/official as well as the mirror checker tool at http://mirror.debian.org/status.html (which provides information on the up-to-dateness status of mirrors) AUTHOR
Avery Pennarun <apenwarr@gmail.com> This manual page and program have been also enhanced by Filippo Giunchedi <filippo@esaurito.net> and Javier Fernandez-Sanguino <jfs@debian.org> DEBIAN
March 6, 2008 NETSELECT-APT(1)
All times are GMT -4. The time now is 08:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy