Can't...I'm running Linux.
Can't...I'm running Linux.
dargueta@dargueta-laptop:~$ sudo rm -rf /media/windows-partition
Ah... WINE?
lol
I'll see if the script works, otherwise I'll think of something else...
YAY!
The script worked
Thanks a heap!
Finished product [also changed the res name];
EDIT: After testing a few files, found that they were all the same and not portable.Code:#!/usr/bin/env perl use strict; use warnings; use POSIX; #declare whitespace-trimming function defined later sub trim($); my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','',''); #open ip list file open(IPFILE,"<iplist.csv") or die "Failed to open IP list file."; #read all lines into array my (@ipfile,$i,$total); @ipfile = <IPFILE>; #for each line in the ip file... $i = 0; $total = 0; foreach(@ipfile) { #strip leading and trailing spaces off the line my $thisline = $_; chomp($thisline); #use regular expressions to pull the ip address from the line. ($currhost,$currip) = split(/\,/,$thisline); #remove leading and trailing whitespace $hostlist[$i] = trim($currhost); $iplist[$i] = trim($currip); ++$i; ++$total; } #close ip list file close(IPFILE); #open template file open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file."; #for each ip address in the list... for($i = 0; $i < $total; ++$i) { #load entire file into single string... #undefine end-of-record variable, which is \n by default. this will result #in the file being divided up into an array of lines instead of one single #string like we want. undef $/; #read the file into $template. $template = <CPPTEMPLATE>; #reset $/ to avoid problems. $/ = "\n"; #get the current ip & host $currip = $iplist[$i]; $currhost = $hostlist[$i]; #open the output file open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing."; #replace all instances of __PUTIPHERE__ in the template file with the #current ip address. $template =~ s/__PUTIPHERE__/$currip/g; #print the result to the output file. print CPPOUT $template; #close the output file close(CPPOUT); #compile `rc VNC.rc /fo "$currhost.res"`; `cl /clr $currhost.cpp`; `link VNC.res $currhost.obj /out:$currhost.exe`; #rewind to beginning of template file to read again seek(CPPTEMPLATE,0,SEEK_SET); } #close template file close(CPPTEMPLATE); #exit 1; #### sub trim($) { my $str = shift(@_); if(not defined $str){ return ''; } $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; }
Just double checked everything;
1. The files aren't portable
2. All .cpp files are the same, only difference is names. This means that they all have the SAME IP Address.
Please fix the script.
Thanks in advance,
Panarchy
BTW: Thought it may be helpful, here's the .cpp file again;
Code:// VNC.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #include <windows.h> #include <tchar.h> #include <iostream> #ifdef UNICODE #define tcout wcout #else #define tcout cout #endif int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; TCHAR lpCmdLine[MAX_PATH] = {0}; ::ExpandEnvironmentStrings(_T("\"%ProgramFiles%\\UltraVNC\\VNCviewer.exe\""), lpCmdLine, MAX_PATH); std::tcout << _T("Command line : ") << lpCmdLine << std::endl; lstrcat(lpCmdLine,_T("/connect 127.0.0.1 /user PseudoAd /password Adm#in@!")); BOOL bRet = ::CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi); return 0; }
I don't see __PUTIPHERE__ anywhere. I think you need to replace 127.0.0.1 with that, if I'm reading your code right. (Doesn't really make sense to remotely log into yourself anyway, at least that I can think of.)
dargueta@dargueta-laptop:~$ sudo rm -rf /media/windows-partition
Thanks...
Since I've made some changes, the script no longer works;
Any ideas?Code:#!/usr/bin/env perl use strict; use warnings; use POSIX; #declare whitespace-trimming function defined later sub trim($); my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','',''); #open ip list file open(IPFILE,"<iplist.csv") or die "Failed to open IP list file."; #read all lines into array my (@ipfile,$i,$total); @ipfile = <IPFILE>; #for each line in the ip file... $i = 0; $total = 0; foreach(@ipfile) { #strip leading and trailing spaces off the line my $thisline = $_; chomp($thisline); #use regular expressions to pull the ip address from the line. ($currhost,$currip) = split(/\,/,$thisline); #remove leading and trailing whitespace $hostlist[$i] = trim($currhost); $iplist[$i] = trim($currip); ++$i; ++$total; } #close ip list file close(IPFILE); #open template file open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file."; #for each ip address in the list... for($i = 0; $i < $total; ++$i) { #load entire file into single string... #undefine end-of-record variable, which is \n by default. this will result #in the file being divided up into an array of lines instead of one single #string like we want. undef $/; #read the file into $template. $template = <CPPTEMPLATE>; #reset $/ to avoid problems. $/ = "\n"; #get the current ip & host $currip = $iplist[$i]; $currhost = $hostlist[$i]; #open the output file open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing."; #replace all instances of __PUTIPHERE__ in the template file with the #current ip address. $template =~ s/__PUTIPHERE__/$currip/g; #print the result to the output file. print CPPOUT $template; #close the output file close(CPPOUT); #compile `rc VNC.rc /fo "$currhost.res"`; `cl /clr $currhost.cpp`; `link VNC.res $currhost.obj /out:$currhost.exe`; `mt.exe manifest "$currhost".manifest -outputresource:"$currhost.exe";` #rewind to beginning of template file to read again seek(CPPTEMPLATE,0,SEEK_SET); } #close template file close(CPPTEMPLATE); #exit 1; #### sub trim($) { my $str = shift(@_); if(not defined $str){ return ''; } $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; }
All I've added is more apostrophe's, now situated [where needed] for the $currhost, as the script hadn't been working with spaces. Also added the line to embed the manifest.
Please point out the problem within the script.
Thanks in advance,
Panarchy
1) In your call to mt.exe, move the semicolon outside the backticks.
2) Get rid of the quotes around $currhost, or put them around the entire file name, not just the variable. You shouldn't really need them unless there's a space in the host name. From the CSV file you showed me, it didn't look like there would be any.
Code:#compile `rc VNC.rc /fo $currhost.res`; `cl /clr $currhost.cpp`; `link VNC.res $currhost.obj /out:$currhost.exe`; `mt.exe manifest $currhost.manifest -outputresource:$currhost.exe`;
Last edited by dargueta; 08-06-2009 at 07:02 AM. Reason: Forgot to explain
dargueta@dargueta-laptop:~$ sudo rm -rf /media/windows-partition
Thanks, I'll give that a go on Monday.
And yes, the CSV file does have multiple hosts with spaces in them...
Ugh. Leave the quotes in, then. Just put them around the entire file name, extension included.
dargueta@dargueta-laptop:~$ sudo rm -rf /media/windows-partition
Okay, thanks. Will do.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum