<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scriptygoddess &#187; Admin-type scripts</title>
	<atom:link href="http://www.scriptygoddess.com/archives/category/admin-type-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptygoddess.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 13:58:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Command Prompt Part II &#8211; Regular Expressions</title>
		<link>http://www.scriptygoddess.com/archives/2003/03/12/php-command-prompt-part-ii-regular-expressions/</link>
		<comments>http://www.scriptygoddess.com/archives/2003/03/12/php-command-prompt-part-ii-regular-expressions/#comments</comments>
		<pubDate>Wed, 12 Mar 2003 21:19:27 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Admin-type scripts]]></category>

		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/03/12/php-command-prompt-part-ii-regular-expressions/</guid>
		<description><![CDATA[How often has it happened that you have a few hundred pages, with something that needs to be changed on each page? Luckily, PHP >= 4.2.0 ships with PCRE enabled by default, opening up the power of regular expressions to PHP scripters. I&#039;m not going to give a primer on REs (Regular Expressions), but if [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>How often has it happened that you have a few hundred pages, with something that needs to be changed on each page? Luckily, PHP >= 4.2.0 ships with PCRE enabled by default, opening up the power of regular expressions to PHP scripters.</p>
<p>I&#039;m not going to give a primer on REs (Regular Expressions), but if you don&#039;t know about them you should really sit right down &#038; teach yourself. O&#039;Reilly has an excellent book on them, and the program Visual REGEXP (search Freshmeat) is a great learning tool.</p>
<p>If you need help on running PHP from the command prompt, see my earlier post on the topic.</p>
<p>Here&#039;s the setup:<br />
<span id="more-990"></span><br />
The situation:<br />
I have 100 old web pages where I want to replace all the font tags with a standard one. (Yes, this is why you should use CSS) This is a bit simplified, but you should easily be able to extend this script to replace only the &#034;face&#034; attribute for example.</p>
<p>The Script:</p>
<h3>$dirpath=&#034;/usr/wget/dev/&#034;;</p>
<p>$pattern=&#034;/<&#92;s*font[^>]*>/&#034;;<br />
$replace=&#034;&lt;font face=&#92;&#034;Verdana&#92;&#034; size=&#92;&#034;2&#92;&#034;&#038;glt&#034;;</p>
<p>if ($handle = opendir($dirpath)) {<br />
        while (false !== ($file = readdir($handle))) {<br />
                if (is_file($file) &#038;&#038; fnmatch(&#034;*html&#034;, $file)) {<br />
                        $lines = file($file);<br />
                        foreach ($lines as $line_num => $lines ) {<br />
                                echo &#034;$file&#92;n&#034;;<br />
                                echo &#034;Old:$lines&#92;n&#034;;<br />
                                $lines=preg_replace($pattern, $replace, $lines);<br />
                                echo &#034;New:$lines&#92;n&#034;;<br />
                        }<br />
                }<br />
        }<br />
        closedir($handle);<br />
}</p>
</h3>
<p>The important lines are $pattern, $replace &#038; the preg_replace function. I&#039;ve left out writing it back to a file to save space.</p>
<p>$pattern is a RE matching all tags with &#034;font&#034; in them, and grabbing the entire tag.<br />
$replace is obviously what I want to replace the old font tags with.<br />
The preg_replace function does all the work, matching the pattern to the string $lines &#038; if its a match, replacing with $replace. If there is no match, no replacement is made.</p>
<p>Again, you can easily leverage your knowledge of PHP to write some simple administrative scripts to make your life easier&#8230;</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.scriptygoddess.com/archives/2003/03/12/php-command-prompt-part-ii-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP at the command prompt</title>
		<link>http://www.scriptygoddess.com/archives/2003/03/11/php-at-the-command-prompt/</link>
		<comments>http://www.scriptygoddess.com/archives/2003/03/11/php-at-the-command-prompt/#comments</comments>
		<pubDate>Tue, 11 Mar 2003 14:46:17 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Admin-type scripts]]></category>

		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/03/11/php-at-the-command-prompt/</guid>
		<description><![CDATA[Figured it was about time I actually posted something&#8230; Little known to many people, PHP actually makes an excellent system level scripting language. Let&#039;s take a quick look at scrapping Perl &#038; using PHP for a simple problem. Setup: I&#039;ve got a bunch of m3u files that contain reference to single mp3 files on a [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Figured it was about time I actually posted something&#8230;</p>
<p>Little known to many people, PHP actually makes an excellent system level scripting language. Let&#039;s take a quick look at scrapping Perl &#038; using PHP for a simple problem.</p>
<p>Setup:<br />
I&#039;ve got a bunch of m3u files that contain reference to single mp3 files on a friend&#039;s web server. I want to download all the mp3s, but don&#039;t want to open each m3u file &#038; copy and paste the http link. Let&#039;s use PHP for the task.<br />
<span id="more-986"></span><br />
First off, this depends on how you have PHP installed, esp. on Linux/Unix systems. If PHP is installed as an apxs Apache module, then you will need have an additional install of PHP. Luckily, this is easy. Download PHP, &#038; enter the source directory &#038; just run &#034;./configure&#034; with no options. This will configure PHP to install binaries under &#034;/usr/local/lib/&#034; and will not touch your existing Apache installs. Windows users would just have to make sure the PHP install dir and php.exe is in your path.</p>
<p>I&#039;m running this script on a Unix system, so I can make use of an excellent utility called wget, which is a command line utility to download files via HTTP and is very configurable.</p>
<p>On with the script!</p>
<p><b><br />
// Define the path to the files you want to download from<br />
$dirpath=&#034;/usr/wget/mydir/audio/&#034;;</p>
<p>// Options for wget may vary.. use wget &#8211;help<br />
$command=&#034;wget -o errors.wget -c &#034;;</p>
<p>// List all files in the dir. Swipped from php.net<br />
if ($handle = opendir($dirpath)) {</p>
<p>        // Recurse over $dirpath &#038; get a pointer to each handle<br />
        while (false !== ($file = readdir($handle))) {</p>
<p>                // Check its a file, and match to your pattern<br />
                // (if you have multiple file types in the dir)<br />
                // fnmatch() is available only in PHP >= 4.3.0<br />
                if (is_file($file) &#038;&#038; fnmatch(&#034;*m3u&#034;, $file)) {</p>
<p>                        // file_get_contents PHP >= 4.3.0<br />
                        $url=file_get_contents($file);</p>
<p>                        // Be careful using system() in web scripts<br />
                        system($command.$url);<br />
                }<br />
        }</p>
<p>        // Don&#039;t forget to close the handle <img src='http://www.scriptygoddess.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
        closedir($handle);<br />
}<br />
</b></p>
<p>Notes: This is run from the command prompt by: php filename.php<br />
This invokes the PHP interpreter &#038; runs the script.</p>
<p>Its a simple script, but could easily be adapted to renaming a large number of files, displaying the contents of many files, etc. PHP has pretty good string &#038; file handling functions (and getting better with each release).</p>
<p>For hardened Perl users, PHP looks in its infancy, but for simple system tasks, why not use your PHP skills?</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.scriptygoddess.com/archives/2003/03/11/php-at-the-command-prompt/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Friendly error pages using PHP and .htaccess</title>
		<link>http://www.scriptygoddess.com/archives/2002/12/08/friendly-error-pages-using-php-and-htaccess/</link>
		<comments>http://www.scriptygoddess.com/archives/2002/12/08/friendly-error-pages-using-php-and-htaccess/#comments</comments>
		<pubDate>Sun, 08 Dec 2002 18:55:02 +0000</pubDate>
		<dc:creator>amy</dc:creator>
				<category><![CDATA[Admin-type scripts]]></category>

		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2002/12/08/friendly-error-pages-using-php-and-htaccess/</guid>
		<description><![CDATA[I know that we&#039;ve posted about .htaccess files and friendly error pages before, but after some questions from my spouse, I decided to write up something more along the lines of a package of scripts. It contains a bit of optional logging, if you want to keep an eye on the details of your errors, [...]


Related posts:<ol><li><a href='http://www.scriptygoddess.com/archives/2009/10/07/delink-pages-plugin/' rel='bookmark' title='Permanent Link: Delink Pages Plugin'>Delink Pages Plugin</a> <small>(Plugin and this post last updated: 10/20/2009 &#8211; Latest Plugin...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I know that we&#039;ve posted about .htaccess files and friendly error pages before, but after some questions from my spouse, I decided to write up something more along the lines of a package of scripts.  It contains a bit of optional logging, if you want to keep an eye on the details of your errors, but that can be turned off if you want.</p>
<p>My full entry (although not much longer than this) about the package is <a href="http://domesticat.net/archives/entry.php?e=776" target="_blank">available here</a>; you can also <a href="http://domesticat.net/misc/making_friendly_error_pages.zip">download the zip file</a> and just work from the README I&#039;ve included.</p>


<p>Related posts:<ol><li><a href='http://www.scriptygoddess.com/archives/2009/10/07/delink-pages-plugin/' rel='bookmark' title='Permanent Link: Delink Pages Plugin'>Delink Pages Plugin</a> <small>(Plugin and this post last updated: 10/20/2009 &#8211; Latest Plugin...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.scriptygoddess.com/archives/2002/12/08/friendly-error-pages-using-php-and-htaccess/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introduction to AD</title>
		<link>http://www.scriptygoddess.com/archives/2002/10/05/introduction-to-ad/</link>
		<comments>http://www.scriptygoddess.com/archives/2002/10/05/introduction-to-ad/#comments</comments>
		<pubDate>Sun, 06 Oct 2002 02:53:53 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Admin-type scripts]]></category>

		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2002/10/05/introduction-to-ad/</guid>
		<description><![CDATA[This is an introduction to a couple of postings I&#039;ll be writing on system admin style scripting. Web scripting is great, but its good to see how the skills you aquire scripting for the web can spill over into &#034;backend&#034; style administration work. That said, lets get into Active Directory (AD), and how to script [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This is an introduction to a couple of postings I&#039;ll be writing on system admin style scripting. Web scripting is great, but its good to see how the skills you aquire scripting for the web can spill over into &#034;backend&#034; style administration work. That said, lets get into Active Directory (AD), and how to script against it.</p>
<p><b>What is AD?</b></p>
<p>AD is basically a Microsoft based implementation of LDAP (Light Directory Access Protocol), which is a hierarchical database of objects (users, computers, etc). LDAP is an open, standard based protocol, meaning that LDAP enabled applications should be able to work with AD. Since this will probably be a long article, please read on&#8230;<br />
<span id="more-852"></span><br />
AD is built into Win2000 servers, and is the preferred way of setting up Win2K networks. It functions like this:<br />
You have a &#034;root&#034; domain (xyz.com)<br />
You have servers off that root (server.xyz.com)<br />
You have objects in that server (computer.server.xyz.com)</p>
<p>Its modeled after a DNS way of looking at things, but the syntax is a little different than making http:// style requests. A LDAP (and as a result AD) query looks like this:<br />
ldap://cn=computer,ou=serverdomain,dc=xyz,dc=com</p>
<p>here&#039;s what things stand for:<br />
cn = common name &#8211; the name of the object you are looking at<br />
ou = organizational unit &#8211; these are grouping that you can put objects into, and do not correspond to &#034;real world&#034; objects.. they are just storage units<br />
dc = domain component &#8211; just the chunks that make up the domain you are in (for this page, it would be dn=scriptygoddess,dn=com)</p>
<p>The cool thing is that each object can have attributes, like location, name, address, and so on. In the next posting I&#039;ll show you how to map all the computers in a lab to all the printers in the lab, without touching each machine, and in a few (under 20) lines of code&#8230;</p>
<p>I should add that I work for a large school district, where we have situations like this all the time, and since students love to fiddle, they constantly disconnect printer mappings on the machines. With this script I can easily map printers in the logon script, so even if they disconnect the printers, they just have to re-logon to get the mappings again. This can easily be abstracted out to the department, where everyone needs to map to a single laser printer. If you use AD/Win2K servers in the dept, you can easily have everyone map the printer.</p>
<p>I should add that I am certainly not a MS advocate, quite the opposite infact. It just so happens that Im stuck scripting for MS products at work, so I thought I would share some knowledge&#8230;</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.scriptygoddess.com/archives/2002/10/05/introduction-to-ad/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.448 seconds -->
