<?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>Scripting Archives - CNERIS</title>
	<atom:link href="https://cneris.com/en/category/system-administration/scripting-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://cneris.com/en/category/system-administration/scripting-en/</link>
	<description></description>
	<lastBuildDate>Sun, 03 Nov 2024 17:42:56 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Error: Terminating since out of inotify watches. Consider increasing /proc/sys/fs/inotify/max_user_watches</title>
		<link>https://cneris.com/en/error-terminating-since-out-of-inotify-watches-consider-increasing-proc-sys-fs-inotify-max_user_watches-en/</link>
					<comments>https://cneris.com/en/error-terminating-since-out-of-inotify-watches-consider-increasing-proc-sys-fs-inotify-max_user_watches-en/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 03 Nov 2024 17:42:35 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Dedicated servers]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[inotify watches]]></category>
		<category><![CDATA[max_user_watches]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2699</guid>

					<description><![CDATA[<p>Error: The error means that the system has reached the maximum number of "inotify watches," which limits the ability to monitor files and directories. This typically happens when there are many applications or processes trying to observe file and directory changes. Solution: To increase the inotify watches limit, follow these steps: Open a terminal and [...]</p>
<p>The post <a href="https://cneris.com/en/error-terminating-since-out-of-inotify-watches-consider-increasing-proc-sys-fs-inotify-max_user_watches-en/">Error: Terminating since out of inotify watches. Consider increasing /proc/sys/fs/inotify/max_user_watches</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Error:</strong> The error means that the system has reached the maximum number of &#8220;inotify watches,&#8221; which limits the ability to monitor files and directories. This typically happens when there are many applications or processes trying to observe file and directory changes.</p>
<p><strong>Solution:</strong> To increase the <code>inotify watches</code> limit, follow these steps:</p>
<ol>
<li>Open a terminal and check the current value with:
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-built_in">cat</span> /proc/sys/fs/inotify/max_user_watches<br />
</code></div>
</div>
</li>
<li>Temporarily increase the value (e.g., to 524288) by running:
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">sudo sysctl fs.inotify.max_user_watches=524288<br />
</code></div>
</div>
</li>
<li>To make the change permanent, edit the <code>/etc/sysctl.conf</code> file:
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">sudo nano /etc/sysctl.conf<br />
</code></div>
</div>
</li>
<li>Add this line at the end of the file:
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">fs.inotify.max_user_watches=524288<br />
</code></div>
</div>
</li>
<li>Save the file and apply the change with:
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">sudo sysctl -p<br />
</code></div>
</div>
</li>
</ol>
<p>After these steps, the system should allow more <code>inotify</code> watchers, and the error should no longer appear.</p>
<p>The post <a href="https://cneris.com/en/error-terminating-since-out-of-inotify-watches-consider-increasing-proc-sys-fs-inotify-max_user_watches-en/">Error: Terminating since out of inotify watches. Consider increasing /proc/sys/fs/inotify/max_user_watches</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/error-terminating-since-out-of-inotify-watches-consider-increasing-proc-sys-fs-inotify-max_user_watches-en/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.</title>
		<link>https://cneris.com/en/a-php-session-was-created-by-a-session_start-function-call-this-interferes-with-rest-api-and-loopback-requests-the-session-should-be-closed-by-session_write_close-before-making-any-http-requests-2/</link>
					<comments>https://cneris.com/en/a-php-session-was-created-by-a-session_start-function-call-this-interferes-with-rest-api-and-loopback-requests-the-session-should-be-closed-by-session_write_close-before-making-any-http-requests-2/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 29 Oct 2024 09:09:24 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Dedicated servers]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[session_close]]></category>
		<category><![CDATA[session_start]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2680</guid>

					<description><![CDATA[<p>This error occurs because the session_start() function is creating a PHP session, which interferes with REST API and loopback requests in WordPress. To resolve this: Locate the session_start() code Search your theme or active plugins for the session_start() function. It may be in the theme’s functions.php file or in a custom plugin. Add session_write_close() after [...]</p>
<p>The post <a href="https://cneris.com/en/a-php-session-was-created-by-a-session_start-function-call-this-interferes-with-rest-api-and-loopback-requests-the-session-should-be-closed-by-session_write_close-before-making-any-http-requests-2/">A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This error occurs because the <code>session_start()</code> function is creating a PHP session, which interferes with REST API and loopback requests in WordPress. To resolve this:</p>
<ol>
<li><strong>Locate the <code>session_start()</code> code</strong><br />
Search your theme or active plugins for the <code>session_start()</code> function. It may be in the theme’s <code>functions.php</code> file or in a custom plugin.</li>
<li><strong>Add <code>session_write_close()</code> after <code>session_start()</code></strong><br />
Ensure <code>session_write_close()</code> is called after each <code>session_start()</code> call, before making any HTTP requests. This will close the session and allow the REST API to work correctly. For example:</p>
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-php"><span class="hljs-title function_ invoke__">session_start</span>();<br />
<span class="hljs-comment">// Your code here</span><br />
<span class="hljs-title function_ invoke__">session_write_close</span>();<br />
</code></div>
</div>
</li>
<li><strong>Use the <code>init</code> hook in WordPress</strong><br />
If <code>session_start()</code> needs to be in <code>functions.php</code>, make sure to wrap it in the <code>init</code> hook and use <code>session_write_close()</code> like this:</p>
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-php"><span class="hljs-title function_ invoke__">add_action</span>(<span class="hljs-string">'init'</span>, function() {<br />
    <span class="hljs-keyword">if</span> (!<span class="hljs-title function_ invoke__">session_id</span>()) {<br />
        <span class="hljs-title function_ invoke__">session_start</span>();<br />
        <span class="hljs-title function_ invoke__">session_write_close</span>();<br />
    }<br />
});</code></div>
</div>
</li>
</ol>
<p>The post <a href="https://cneris.com/en/a-php-session-was-created-by-a-session_start-function-call-this-interferes-with-rest-api-and-loopback-requests-the-session-should-be-closed-by-session_write_close-before-making-any-http-requests-2/">A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/a-php-session-was-created-by-a-session_start-function-call-this-interferes-with-rest-api-and-loopback-requests-the-session-should-be-closed-by-session_write_close-before-making-any-http-requests-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How you can set a default featured image for each post category</title>
		<link>https://cneris.com/en/how-you-can-set-a-default-featured-image-for-each-post-category/</link>
					<comments>https://cneris.com/en/how-you-can-set-a-default-featured-image-for-each-post-category/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 29 Oct 2024 08:59:48 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Dedicated servers]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[featured image]]></category>
		<category><![CDATA[post category]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2671</guid>

					<description><![CDATA[<p>In WordPress, you can set a default featured image for each post category by using a snippet of code in your theme's functions.php file. This code checks if a post has a featured image assigned; if not, it sets a default image based on the post's category. Code to Assign Default Featured Image by Category [...]</p>
<p>The post <a href="https://cneris.com/en/how-you-can-set-a-default-featured-image-for-each-post-category/">How you can set a default featured image for each post category</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In WordPress, you can set a default featured image for each post category by using a snippet of code in your theme&#8217;s <code>functions.php</code> file. This code checks if a post has a featured image assigned; if not, it sets a default image based on the post&#8217;s category.</p>
<h4>Code to Assign Default Featured Image by Category</h4>
<ol>
<li>Open your theme&#8217;s <code>functions.php</code> file (preferably a child theme to avoid losing changes with updates).</li>
<li>Add the following code, replacing the URLs with your default images for each category:</li>
</ol>
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-php"><br />
</code></div>
</div>
<p>function set_default_thumbnail($post_id) {<br />
if (has_post_thumbnail($post_id)) {<br />
return;<br />
}</p>
<p>// Define default images for each category<br />
$default_images = [<br />
&#8216;category-1&#8217; =&gt; &#8216;https://your-site.com/wp-content/uploads/category-image1.jpg&#8217;,<br />
&#8216;category-2&#8217; =&gt; &#8216;https://your-site.com/wp-content/uploads/category-image2.jpg&#8217;,<br />
&#8216;category-3&#8217; =&gt; &#8216;https://your-site.com/wp-content/uploads/category-image3.jpg&#8217;,<br />
];</p>
<p>// Get post categories<br />
$categories = get_the_category($post_id);</p>
<p>// Check if categories are assigned and find a matching default image<br />
foreach ($categories as $category) {<br />
if (array_key_exists($category-&gt;slug, $default_images)) {<br />
$image_url = $default_images[$category-&gt;slug];</p>
<p>// Download image and set as featured image<br />
$image_id = attach_image_from_url($image_url, $post_id);<br />
if ($image_id) {<br />
set_post_thumbnail($post_id, $image_id);<br />
}<br />
break;<br />
}<br />
}<br />
}<br />
add_action(&#8216;save_post&#8217;, &#8216;set_default_thumbnail&#8217;);</p>
<p>// Function to download and attach the image to the post<br />
function attach_image_from_url($image_url, $post_id) {<br />
$upload_dir = wp_upload_dir();<br />
$image_data = file_get_contents($image_url);<br />
$filename = basename($image_url);</p>
<p>if (wp_mkdir_p($upload_dir[&#8216;path&#8217;])) {<br />
$file = $upload_dir[&#8216;path&#8217;] . &#8216;/&#8217; . $filename;<br />
} else {<br />
$file = $upload_dir[&#8216;basedir&#8217;] . &#8216;/&#8217; . $filename;<br />
}</p>
<p>file_put_contents($file, $image_data);</p>
<p>$wp_filetype = wp_check_filetype($filename, null);<br />
$attachment = [<br />
&#8216;post_mime_type&#8217; =&gt; $wp_filetype[&#8216;type&#8217;],<br />
&#8216;post_title&#8217; =&gt; sanitize_file_name($filename),<br />
&#8216;post_content&#8217; =&gt; &#8221;,<br />
&#8216;post_status&#8217; =&gt; &#8216;inherit&#8217;<br />
];</p>
<p>$attach_id = wp_insert_attachment($attachment, $file, $post_id);<br />
require_once(ABSPATH . &#8216;wp-admin/includes/image.php&#8217;);<br />
$attach_data = wp_generate_attachment_metadata($attach_id, $file);<br />
wp_update_attachment_metadata($attach_id, $attach_data);</p>
<p>return $attach_id;<br />
}</p>
<h4>Code Explanation</h4>
<ul>
<li><strong><code>$default_images</code></strong>: Defines default images for each category using the category slug as the key and the image URL as the value.</li>
<li><strong><code>set_default_thumbnail</code></strong>: This function runs when a post is saved. If the post has no featured image, it finds the first category with a default image in <code>$default_images</code> and sets it as the featured image.</li>
<li><strong><code>attach_image_from_url</code></strong>: This function downloads the image from the URL and attaches it to the post as a media file, making it the featured image.</li>
</ul>
<p>This code will automatically assign a default featured image for new or edited posts based on their category.</p>
<p><strong>Note</strong>: Make sure to test this code in a development environment before implementing it on your live site, and replace the example URLs with your actual default image URLs.</p>
<p>The post <a href="https://cneris.com/en/how-you-can-set-a-default-featured-image-for-each-post-category/">How you can set a default featured image for each post category</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/how-you-can-set-a-default-featured-image-for-each-post-category/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Traffic Bot in Python</title>
		<link>https://cneris.com/en/traffic-bot-in-python/</link>
					<comments>https://cneris.com/en/traffic-bot-in-python/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 02 Oct 2024 16:32:25 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[traffic bot]]></category>
		<category><![CDATA[traffic box python]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2329</guid>

					<description><![CDATA[<p>There is a Traffic Bot written in Python that can be used to generate automated web traffic. This type of bot can be useful for performance testing, user simulation, or web development experiments. Below is an example of code and a small usage guide. Python Code Example: This script uses the requests library to simulate [...]</p>
<p>The post <a href="https://cneris.com/en/traffic-bot-in-python/">Traffic Bot in Python</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There is a <strong>Traffic Bot</strong> written in <strong>Python</strong> that can be used to generate automated web traffic. This type of bot can be useful for performance testing, user simulation, or web development experiments. Below is an example of code and a small usage guide.</p>
<h4>Python Code Example:</h4>
<p>This script uses the <strong>requests</strong> library to simulate multiple visits to a specific URL.</p>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="flex items-center text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"><span class="hljs-keyword">import</span> requests<br />
<span class="hljs-keyword">import</span> time</code></code><span class="hljs-comment"># URL of the website you want to visit</span><br />
url = <span class="hljs-string">&#8216;https://your-site.com&#8217;</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-comment"># Number of visits you want to make</span><br />
visits = <span class="hljs-number">100</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-comment"># Time interval between visits in seconds</span><br />
interval = <span class="hljs-number">5</span></p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(visits):<br />
response = requests.get(url)<br />
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&#8217;Visit <span class="hljs-subst">{i+<span class="hljs-number">1</span>}</span>: <span class="hljs-subst">{response.status_code}</span>&#8216;</span>)<br />
time.sleep(interval)</p>
</div>
</div>
<h4>Usage Guide:</h4>
<ol>
<li><strong>Installing Dependencies</strong>: You need to install the <code>requests</code> library to run this script:
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">pip install requests<br />
</code></div>
</div>
</li>
<li><strong>Customization</strong>:
<ul>
<li>Modify the <code>url</code> variable to point to the site you want to visit.</li>
<li>Adjust the <code>visits</code> to define how many times the bot should visit the site.</li>
<li>Use the <code>interval</code> to set the time between each request (in seconds).</li>
</ul>
</li>
<li><strong>Execution</strong>: Save the code in a file, for example, <code>traffic_bot.py</code>, and run it:
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">python traffic_bot.py<br />
</code></div>
</div>
</li>
</ol>
<p>This basic bot simply visits a webpage multiple times, simulates traffic, and prints the request status.</p>
<p>The post <a href="https://cneris.com/en/traffic-bot-in-python/">Traffic Bot in Python</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/traffic-bot-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Detect Duplicate Links on a Website</title>
		<link>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/</link>
					<comments>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 02 Oct 2024 16:01:30 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[duplicated links]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[repeate links]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2321</guid>

					<description><![CDATA[<p>Detecting duplicate links on a website is important for SEO optimization and improving user experience. Here are several ways to achieve it: Using online tools: Tools like Screaming Frog or Ahrefs allow you to crawl all the links on a website and show you if there are any duplicates. Screaming Frog has a specific feature [...]</p>
<p>The post <a href="https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/">How to Detect Duplicate Links on a Website</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Detecting duplicate links on a website is important for SEO optimization and improving user experience. Here are several ways to achieve it:</p>
<ol>
<li><strong>Using online tools</strong>:
<ul>
<li>Tools like <strong>Screaming Frog</strong> or <strong>Ahrefs</strong> allow you to crawl all the links on a website and show you if there are any duplicates.</li>
<li><strong>Screaming Frog</strong> has a specific feature to track all internal and external links and find duplicates.</li>
</ul>
</li>
<li><strong>With custom scripts</strong>:
<ul>
<li>You can use a <strong>Python script</strong> with the <strong>BeautifulSoup</strong> library to extract all links and then check if any are duplicated.</li>
</ul>
<p>Example in Python:</p>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"><span class="hljs-keyword">import</span> requests<br />
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup<br />
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter</code></code>url = <span class="hljs-string">&#8216;https://yoursite.com&#8217;</span><br />
response = requests.get(url)<br />
soup = BeautifulSoup(response.text, <span class="hljs-string">&#8216;html.parser&#8217;</span>)</p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code>links = [link.get(<span class="hljs-string">&#8216;href&#8217;</span>) <span class="hljs-keyword">for</span> link <span class="hljs-keyword">in</span> soup.find_all(<span class="hljs-string">&#8216;a&#8217;</span>) <span class="hljs-keyword">if</span> link.get(<span class="hljs-string">&#8216;href&#8217;</span>)]<br />
duplicates = [item <span class="hljs-keyword">for</span> item, count <span class="hljs-keyword">in</span> Counter(links).items() <span class="hljs-keyword">if</span> count &gt; <span class="hljs-number">1</span>]</p>
<p><code class="!whitespace-pre hljs language-python"><code class="!whitespace-pre hljs language-python"></code></code><span class="hljs-built_in">print</span>(<span class="hljs-string">f&#8217;Duplicate links: <span class="hljs-subst">{duplicates}</span>&#8216;</span>)</p>
</div>
</div>
</li>
<li><strong>Using browser extensions</strong>:
<ul>
<li>Some browser extensions like <strong>Check My Links</strong> for Chrome allow you to verify links on a page and detect if any are duplicated or broken.</li>
</ul>
</li>
</ol>
<p>The post <a href="https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/">How to Detect Duplicate Links on a Website</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/how-to-detect-duplicate-links-on-a-website/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Usage and Examples of the grep</title>
		<link>https://cneris.com/en/usage-and-examples-of-the-grep/</link>
					<comments>https://cneris.com/en/usage-and-examples-of-the-grep/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 28 Sep 2024 16:08:48 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Dedicated servers]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2268</guid>

					<description><![CDATA[<p>The grep command is widely used in Unix/Linux systems to search for patterns in text files. It’s useful for filtering lines that match a specific text or regular expression. Basic syntax grep [options] "pattern" file pattern: The text or regular expression you want to search for. file: The file where you want to perform the [...]</p>
<p>The post <a href="https://cneris.com/en/usage-and-examples-of-the-grep/">Usage and Examples of the grep</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <code>grep</code> command is widely used in Unix/Linux systems to search for patterns in text files. It’s useful for filtering lines that match a specific text or regular expression.</p>
<h4><strong>Basic syntax</strong></h4>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep [options] <span class="hljs-string">"pattern"</span> file<br />
</code></div>
</div>
<ul>
<li><code>pattern</code>: The text or regular expression you want to search for.</li>
<li><code>file</code>: The file where you want to perform the search.</li>
</ul>
<h4><strong>Common examples:</strong></h4>
<ol>
<li><strong>Search for a specific word in a file:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep <span class="hljs-string">"word"</span> file.txt<br />
</code></div>
</div>
</li>
<li><strong>Case-insensitive search:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep -i <span class="hljs-string">"word"</span> file.txt<br />
</code></div>
</div>
</li>
<li><strong>Search across multiple files:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep <span class="hljs-string">"word"</span> *.txt<br />
</code></div>
</div>
</li>
<li><strong>Search for lines that do not contain a pattern:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep -v <span class="hljs-string">"word"</span> file.txt<br />
</code></div>
</div>
</li>
<li><strong>Count how many times a word appears in a file:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-main-surface-secondary px-2 font-sans text-xs text-token-text-secondary"></div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep -c <span class="hljs-string">"word"</span> file.txt<br />
</code></div>
</div>
</li>
<li><strong>Show the line number where the word appears:</strong>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">grep -n <span class="hljs-string">"word"</span> file.txt<br />
</code></div>
</div>
</li>
</ol>
<h4><strong>Advanced usage:</strong></h4>
<p>You can combine <code>grep</code> with other commands, such as <code>cat</code> or <code>find</code>, for more complex searches. For example:</p>
<ul>
<li>Find files containing a specific word in a directory:
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative">
<div class="flex items-center text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9"></div>
<div class="sticky top-9 md:top-[5.75rem]"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">find . -<span class="hljs-built_in">type</span> f | xargs grep <span class="hljs-string">"word"</span></code></div>
</div>
</li>
</ul>
<p>The post <a href="https://cneris.com/en/usage-and-examples-of-the-grep/">Usage and Examples of the grep</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/usage-and-examples-of-the-grep/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Python script logging and posting in a Discuz forum</title>
		<link>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/</link>
					<comments>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 28 Sep 2024 15:45:22 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[python script]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2254</guid>

					<description><![CDATA[<p>#!/usr/bin/python3 # -*- coding: utf-8 -*- import logging import re import requests class AutoDiscuz: LOGIN_URL = "/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes" LOGIN_POST = {"username": "", "password": ""} def __init__(self, forum_url, user_name, password): """初始化论坛 url、用户名、密码和代理服务器.""" self.forum_url = forum_url self.user_name = user_name self.password = password self.formhash = None self.is_login = False self.session = requests.Session() logging.basicConfig(level=logging.INFO, format="[%(levelname)1.1s %(asctime)s] %(message)s") def login(self): """登录论坛.""" [...]</p>
<p>The post <a href="https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/">Python script logging and posting in a Discuz forum</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>#!/usr/bin/python3<br />
# -*- coding: utf-8 -*-</p>
<p>import logging<br />
import re</p>
<p>import requests</p>
<p>class AutoDiscuz:<br />
LOGIN_URL = &#8220;/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes&#8221;<br />
LOGIN_POST = {&#8220;username&#8221;: &#8220;&#8221;, &#8220;password&#8221;: &#8220;&#8221;}</p>
<p>def __init__(self, forum_url, user_name, password):<br />
&#8220;&#8221;&#8221;初始化论坛 url、用户名、密码和代理服务器.&#8221;&#8221;&#8221;<br />
self.forum_url = forum_url<br />
self.user_name = user_name<br />
self.password = password<br />
self.formhash = None<br />
self.is_login = False<br />
self.session = requests.Session()<br />
logging.basicConfig(level=logging.INFO,<br />
format=&#8221;[%(levelname)1.1s %(asctime)s] %(message)s&#8221;)</p>
<p>def login(self):<br />
&#8220;&#8221;&#8221;登录论坛.&#8221;&#8221;&#8221;<br />
url = self.forum_url + AutoDiscuz.LOGIN_URL<br />
AutoDiscuz.LOGIN_POST[&#8220;username&#8221;] = self.user_name<br />
AutoDiscuz.LOGIN_POST[&#8220;password&#8221;] = self.password<br />
req = self.session.post(url, data=AutoDiscuz.LOGIN_POST)<br />
if self.user_name in req.text:<br />
self.is_login = True<br />
if self.get_formhash():<br />
logging.info(&#8220;Login success!&#8221;)<br />
return<br />
logging.error(&#8220;Login faild!&#8221;)</p>
<p>def get_formhash(self):<br />
&#8220;&#8221;&#8221;获取 formhash.&#8221;&#8221;&#8221;<br />
req = self.session.get(self.forum_url)<br />
rows = re.findall(<br />
r&#8221;&lt;input type=\&#8221;hidden\&#8221; name=\&#8221;formhash\&#8221; value=\&#8221;(.*?)\&#8221; /&gt;&#8221;, req.text)<br />
if len(rows) != 0:<br />
self.formhash = rows[0]<br />
logging.info(&#8220;Formhash is: &#8221; + self.formhash)<br />
return True<br />
else:<br />
logging.error(&#8220;None formhash!&#8221;)<br />
return False</p>
<p>def reply(self, tid, subject=&#8221;&#8221;, msg=&#8221;6666666666666666666&#8243;):<br />
&#8220;&#8221;&#8221;回帖.&#8221;&#8221;&#8221;<br />
url = self.forum_url + \<br />
&#8220;/forum.php?mod=post&amp;action=reply&amp;replysubmit=yes&amp;inajax=1&amp;tid=&#8221; + \<br />
str(tid)<br />
post_data = {&#8220;formhash&#8221;: self.formhash,<br />
&#8220;message&#8221;: msg, &#8220;subject&#8221;: subject}<br />
content = self.session.post(url, post_data).text<br />
if &#8220;发布成功&#8221; in content:<br />
logging.info(&#8220;Tid: &#8221; + str(tid) + &#8221; reply success!&#8221;)<br />
return True<br />
else:<br />
logging.error(&#8220;Tid: &#8221; + str(tid) + &#8221; reply faild!&#8221;)<br />
return False</p>
<p>def main():<br />
auto_discuz = AutoDiscuz(&#8220;http://url&#8221;, &#8220;account&#8221;, &#8220;password&#8221;)<br />
auto_discuz.login()<br />
if auto_discuz.is_login:<br />
auto_discuz.reply(tid=1000)</p>
<p>if __name__ == &#8220;__main__&#8221;:<br />
main()</p>
<p>The post <a href="https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/">Python script logging and posting in a Discuz forum</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/python-script-logging-and-posting-in-a-discuz-forum/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Base-admin.class.php PHP Fatal error: Uncaught Error: [] operator not supported for strings</title>
		<link>https://cneris.com/en/php-fatal-error-uncaught-error-operator-not-supported-for-strings/</link>
					<comments>https://cneris.com/en/php-fatal-error-uncaught-error-operator-not-supported-for-strings/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 30 Aug 2024 07:21:56 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Dedicated servers]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[fatal error]]></category>
		<category><![CDATA[PHP Fatal error]]></category>
		<category><![CDATA[php issues]]></category>
		<category><![CDATA[php uncaught error]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2214</guid>

					<description><![CDATA[<p>The error you're encountering, "PHP Fatal error: Uncaught Error: [] operator not supported for strings", indicates that in the file base-admin.class.php of the Revolution Slider (or RevSlider) plugin, you are trying to use the [] operator to add a value to a variable that has been declared as a string. The [] operator is used [...]</p>
<p>The post <a href="https://cneris.com/en/php-fatal-error-uncaught-error-operator-not-supported-for-strings/">Base-admin.class.php PHP Fatal error: Uncaught Error: [] operator not supported for strings</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The error you&#8217;re encountering, <strong>&#8220;PHP Fatal error: Uncaught Error: [] operator not supported for strings&#8221;</strong>, indicates that in the file <code>base-admin.class.php</code> of the <strong>Revolution Slider</strong> (or <strong>RevSlider</strong>) plugin, you are trying to use the <code>[]</code> operator to add a value to a variable that has been declared as a string. The <code>[]</code> operator is used to add elements to an array, not to manipulate strings.</p>
<h3>Steps to Resolve the Error:</h3>
<ol>
<li><strong>Locate the problematic file and line:</strong>
<ul>
<li>The error specifies the exact location of the file and line where the problem occurs: <code>/www/httpdocs/wp-content/plugins/revslider/includes/framework/base-admin.class.php</code>.</li>
</ul>
</li>
<li><strong>Edit the file:</strong>
<ul>
<li>Open the file in a text editor or the code editor of your choice.</li>
</ul>
</li>
<li><strong>Find the problematic line:</strong>
<ul>
<li>Go to the line of code that is causing the error. Look for the line that uses the <code>[]</code> operator on a variable that might have been initialized as a string.</li>
</ul>
</li>
<li><strong>Ensure the variable is an array:</strong>
<ul>
<li>Before using the <code>[]</code> operator, check if the variable is an array. If it&#8217;s not, convert it to an array. You can do this as follows:</li>
</ul>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<p>php</p>
<div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center">Copiar código</button></span></div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-php"><span class="hljs-keyword">if</span> (!<span class="hljs-title function_ invoke__">is_array</span>(<span class="hljs-variable">$variable</span>)) {<br />
<span class="hljs-variable">$variable</span> = [];<br />
}<br />
<span class="hljs-variable">$variable</span>[] = <span class="hljs-variable">$value</span>; <span class="hljs-comment">// This is where a value is added to the array</span><br />
</code></div>
</div>
<ul>
<li>If the variable is initialized as a string, convert it to an array:</li>
</ul>
<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<p>php</p>
<div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center">Copiar código</button></span></div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-php"><span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">is_string</span>(<span class="hljs-variable">$variable</span>)) {<br />
<span class="hljs-variable">$variable</span> = [];<br />
}<br />
<span class="hljs-variable">$variable</span>[] = <span class="hljs-variable">$value</span>;<br />
</code></div>
</div>
</li>
<li><strong>Save the changes and test:</strong>
<ul>
<li>After making these changes, save the file and reload the page or functionality that was generating the error.</li>
</ul>
</li>
<li><strong>Update or replace the plugin:</strong>
<ul>
<li>If this solution is complex or the problem persists, consider updating the plugin to the latest version. Sometimes, the plugin developers have already fixed these issues in newer versions.</li>
</ul>
</li>
</ol>
<p>If you&#8217;re not comfortable editing the code, I recommend making a backup of the original file before making any changes. You might also consider contacting the plugin&#8217;s support team for specific assistance.</p>
<p>The post <a href="https://cneris.com/en/php-fatal-error-uncaught-error-operator-not-supported-for-strings/">Base-admin.class.php PHP Fatal error: Uncaught Error: [] operator not supported for strings</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/php-fatal-error-uncaught-error-operator-not-supported-for-strings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Create a Script to Automate Backups on a Dedicated Server with Multiple Vhosts</title>
		<link>https://cneris.com/en/how-to-create-a-script-to-automate-backups-on-a-dedicated-server-with-multiple-vhosts/</link>
					<comments>https://cneris.com/en/how-to-create-a-script-to-automate-backups-on-a-dedicated-server-with-multiple-vhosts/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 23 Aug 2024 20:58:57 +0000</pubDate>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[automate backups]]></category>
		<category><![CDATA[dedicated server]]></category>
		<category><![CDATA[script to automate]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2003</guid>

					<description><![CDATA[<p>Automating backups on a dedicated server hosting multiple websites via vhosts is essential to ensure data security and availability. In this article, you'll learn how to create a Bash script to automate the backup process for different websites hosted on a server with vhosts. I'll include code examples so you can implement it easily. Step [...]</p>
<p>The post <a href="https://cneris.com/en/how-to-create-a-script-to-automate-backups-on-a-dedicated-server-with-multiple-vhosts/">How to Create a Script to Automate Backups on a Dedicated Server with Multiple Vhosts</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Automating backups on a dedicated server hosting multiple websites via vhosts is essential to ensure data security and availability. In this article, you&#8217;ll learn how to create a Bash script to automate the backup process for different websites hosted on a server with vhosts. I&#8217;ll include code examples so you can implement it easily.</p>
<p><strong>Step 1: Setting Up the Environment</strong></p>
<p>Before you start writing the script, make sure your server has SSH access configured and that you have root or sudo privileges. Additionally, you&#8217;ll need a directory where the backups will be stored.</p>
<p><strong>Step 2: Creating the Backup Script</strong></p>
<p>Below is an example of a Bash script that automates backups of the vhosts. This script will compress the files of each website and store them in a backup directory.</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-meta">#!/bin/bash</span><br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-comment"># Directory where backups will be stored</span><br />
backup_dir=<span class="hljs-string">"/var/backups"</span><br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-comment"># Current date</span><br />
<span class="hljs-built_in">date</span>=$(<span class="hljs-built_in">date</span> +<span class="hljs-string">'%Y-%m-%d'</span>)<br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><code class="!whitespace-pre hljs language-bash"><span class="hljs-comment"># Vhosts directory</span><br />
vhosts_dir=<span class="hljs-string">"/etc/apache2/sites-available"</span></code></code><span class="hljs-comment"># Create backup directory if it doesn&#8217;t exist</span><br />
<span class="hljs-built_in">mkdir</span> -p <span class="hljs-string">&#8220;<span class="hljs-variable">$backup_dir</span>/<span class="hljs-variable">$date</span>&#8220;</span></p>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-comment"># Loop through each vhost and perform the backup</span><br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-keyword">for</span> vhost <span class="hljs-keyword">in</span> $(<span class="hljs-built_in">ls</span> <span class="hljs-string">"<span class="hljs-variable">$vhosts_dir</span>"</span>); </code><code class="!whitespace-pre hljs language-bash"><span class="hljs-keyword">do</span><br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">    site_name=$(<span class="hljs-built_in">basename</span> <span class="hljs-string">"<span class="hljs-variable">$vhost</span>"</span> .conf)<br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">    tar -czf <span class="hljs-string">"<span class="hljs-variable">$backup_dir</span>/<span class="hljs-variable">$date</span>/<span class="hljs-variable">$site_name</span>.tar.gz"</span> <span class="hljs-string">"/var/www/<span class="hljs-variable">$site_name</span>"</span><br />
</code></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-keyword">done</span><br />
</code></div>
</div>
<p><strong>Step 3: Scheduling the Script</strong></p>
<p>To have the script run automatically, you can schedule it using cron. To edit the cron, run the following command:</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">$ crontab -e<br />
</code></div>
</div>
<p>Add the following line to have the script run daily at 2 AM:</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"></div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-javascript"><span class="hljs-number">0</span> <span class="hljs-number">2</span> * * * <span class="hljs-regexp">/path/</span>to/script/backup_script.<span class="hljs-property">sh</span><br />
</code></div>
</div>
<p><strong>Conclusion:</strong></p>
<p>Automating backups of your vhosts is an excellent way to ensure your data is protected without the need for manual intervention. This script provides a simple and effective solution for maintaining regular backups of your websites.</p>
<p>The post <a href="https://cneris.com/en/how-to-create-a-script-to-automate-backups-on-a-dedicated-server-with-multiple-vhosts/">How to Create a Script to Automate Backups on a Dedicated Server with Multiple Vhosts</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/how-to-create-a-script-to-automate-backups-on-a-dedicated-server-with-multiple-vhosts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Creating a script for monitoring the free space in the disk and sending an email in case of need</title>
		<link>https://cneris.com/en/creating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-needcreating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-need/</link>
					<comments>https://cneris.com/en/creating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-needcreating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-need/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 22 Aug 2024 22:23:43 +0000</pubDate>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[free space in the disk]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sending an email]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=1995</guid>

					<description><![CDATA[<p>Monitoring disk space is crucial to ensure that servers and systems do not run out of space, which could lead to data loss or system failures. In this article, you will learn how to create a Bash script that monitors disk space and sends an email notification when the available space falls below a specific [...]</p>
<p>The post <a href="https://cneris.com/en/creating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-needcreating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-need/">Creating a script for monitoring the free space in the disk and sending an email in case of need</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Monitoring disk space is crucial to ensure that servers and systems do not run out of space, which could lead to data loss or system failures. In this article, you will learn how to create a Bash script that monitors disk space and sends an email notification when the available space falls below a specific threshold.<br />
Steps to Create the Script<br />
1. Create the Bash Script:<br />
Create a script file, for example, `monitor_space.sh`:<br />
&#8220;`bash<br />
#!/bin/bash</p>
<p># Configuration<br />
THRESHOLD=20 # Minimum percentage of free disk space<br />
EMAIL=&#8221;youremail@example.com&#8221;</p>
<p># Get the percentage of free disk space<br />
FREE_SPACE=$(df / | grep / | awk &#8216;{ print $4 }&#8217; | sed &#8216;s/%//g&#8217;)</p>
<p># Check if free space is below the threshold<br />
if [ &#8220;$FREE_SPACE&#8221; -lt &#8220;$THRESHOLD&#8221; ]; then<br />
# Send warning email<br />
echo &#8220;Warning: Disk space is below $THRESHOLD%. Available space: $FREE_SPACE%.&#8221; | mail -s &#8220;Alert: Low Disk Space&#8221; $EMAIL<br />
fi<br />
&#8220;`</p>
<p>2. Set Permissions:<br />
Make sure the script has execution permissions:<br />
&#8220;`bash<br />
chmod +x monitor_space.sh<br />
&#8220;`</p>
<p>3. Configure Cron Job:<br />
To run the script periodically, you can set it up in cron:<br />
&#8220;`bash<br />
crontab -e<br />
&#8220;`<br />
Add the following line to run the script every hour:<br />
&#8220;`bash<br />
0 * * * * /path/to/script/monitor_space.sh<br />
&#8220;`</p>
<p>Conclusion<br />
With this simple script, you can effectively monitor disk space and receive email alerts when space is low, allowing you to take preventive actions.</p>
<p>The post <a href="https://cneris.com/en/creating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-needcreating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-need/">Creating a script for monitoring the free space in the disk and sending an email in case of need</a> appeared first on <a href="https://cneris.com/en">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/en/creating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-needcreating-a-script-for-monitoring-the-free-space-in-the-disk-and-sending-an-email-in-case-of-need/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
