Centos Network Configuration – is very simple on a full installation. However, I downloaded the Centos’ “Minimal Install” cd and used yum to install various packages I needed.
The simple way to do it if you have a standard installation is to use the Network Administration
Tool (system-config-network), which is a graphical interface to edit the configuration files. Since I haven’t installed this tool, I needed to edit the files manually.
How to Configure Network in Centos from Command Line:
A quick way to see if your interface works and if you can ping internal resources. ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Use your IP addresses.
Note that this is not persistent, at the first reboot, ot first network services restart this will be lost.
For a DHCP address assignment use: ifdown eth0
To get a persistent centos network configuration use the following procedure:
Edit the network configuration file
Edit the configuration file so it contains your IP address configuration as follows: DEVICE="eth0"
This configures your interface with the IP 192.168.0.2 and the netmask 255.255.255.0.
For more info about Centos’ network configuration look here: .
Set up Name Resolution
Name resolution configuration, is more consistent across various Linux distributions. Most of the Linux distros will have the configuration file at /etc/resolv.conf.
Edit this file and change according to your network: vi /etc/resolv.conf
Modify the file so it contains pointers to your DNS servers like this: nameserver 192.168.0.254
As a Windows Network Administrator I always have to make space delete unneeded files, archive old files, compress files that we don’t need but we might need at some point.
I don’t use the same compression method every time, because the scenario is different. Here are a three compression methods for Windows.
Compress Files Using the NTFS Compression
This method of compression only works on NTFS partitions. You don’t have the option for a FAT or FAT32 partition.
The most usual and easier way to do this is to use the Windows’ Graphical Interface and access the Advanced File Properties and select Compress contents to save disk space.
Compact – Compress files or folders from command line
If you would like to compress files from a batch file use this command line variant. Usually if you access the advanced file properties, (right-click => properties and => advanced) you have the option to compress contents to save space. Another good use of the command line is that it gives you a better view of the progress. The graphic interface sometimes hangs and you don’t know if the job is still active.
The command to compress a folder from within the folder is compact /c /s. It compresses all of the files within the folder and marks the folder as compressed so that new files are created compressed.
Why would you choose Compact and not Zipped Folder?
The main reason is that a compacted folder can be used by applications. In other words if the path of a log file points to a compacted folder this is transparent for the application that writes the log file. As a result your log files will be compacted. You cannot do this with Zipped folders or files.
Compress files using the Windows’ built-in zip archiving utility
Why would you choose Compressed (Zipped) Folder over the Compacted Folder?
The zipped Folder has better compression and better portability. The zipped folder has a slightly better compression rate, and you can copy the files to any other Operating System, send them by email and they will retain the compression. The compacted folders will only be compressed on the original location unless you compress the file again at the new destination. Note in the image below the difference between the two file compression formats. The Windows shell has the option to “show NTFS compressed files in color”, which is a great option. Note that the zipped file is slightly smaller than the compacted, (blue colored), one.
Is there a Compressed (zipped) Folder – command line variant?
Unfortunately, there isn’t any Windows built-in option. The good news though is that there is a free archiver that has a command line version as well. 7zip is a great free utility very flexible that manipulates all of the popular archiving file formats.
Compressing from the command line with 7zip is very simple, the simplest command is 7z a NewFolder.zip “New Folder” that compresses the folder New Folder into the archive: NewFolder.zip. For more options and switches type: 7z –h, note that 7z doesn’t understand the /? switch, usual on any Windows application.
Why would you choose 7Zip over the Windows’ built in compressing solutions?
The main reason is flexibility. 7zip has a lot of options/switches that control a lot of the compression aspects and it is very easy to use in a batch file.
An interesting application is to separately archive a lot of folders from a batch file. Let’s say you have 500 folders that you want to archive and you know you will be accessing those folders on a regular. It makes more sense to archive the folders separately and not in one big file. It is easier to access smaller zip files from the Windows shell and keeps the system responsive. To do this manually for 500 folders is a nightmare. Here is a command that runs from a batch file that will compress those folders separately, each folder one zip file:
for /D %%d in (*.*) do 7z a -tzip “%%d.zip” “.\%%d\*”
To run the command from the command line and not from a batch file the command is slightly different:
for /D %d in (*.*) do 7z a -tzip “%d.zip” “.\%d\*”
There are other great archiving utilities such as Winzip, Winrar, Pkzip, etc… They are not free, but you can get a trial-ware which in many cases is good enough for anybody.
A few tips on what to compress and what not.
Usually Installation files are already compressed so there is no benefit in compressing.
Digital photos in a jpg or gif format are already compressed using special algorithms.
PDF files don’t compress.
Text files, (plain text, log files, etc…) compress the best.
Word files can be compressed but not as much as the text files.
Did you ever want to send automatic emails, whether the sending was triggered by an event or just wanted to send the email at a certain time of the day or month?
I am not talking about Email Marketing Software, although that sounds interesting too. I am talking about sending emails from a batch file. You make a backup of a file and need to know when the task was finished or you want to send some files to a group of users, let’s say some weekly reports, logs, the contents of an html form, etc… How do you do that? Here is a real example.
Many people look for an outlook command line to send email, however that is less powerful than my method. At the end of the article you can see a limited way to do that. Before looking at the Outlook solution though, check my solution to send email from command line. It’s powerful, elegant and fast.
How did I Start to Send Emails from Command Line?
I was recently asked to find a solution for sending some huge Excel reports to a list of users. Previously, the application was automatically producing and then sending the reports using Outlook. The application didn’t compress the files and that worked fine until a huge report was requested by the Management. The huge report couldn’t be sent anymore by email because the servers will deny big attachments.
Using third party automatic email attachment compression software, (like Winzip Courier), didn’t work because works with an Outlook message, but this wasn’t the case.
We then decided to let the application do only the report generation and we were going to compress and email the files using other software.
First of all there are several applications of the type “Automatic Email Senders“. The “Automatic Email Senders” software applications are very complex, take space on the hard-drive and cost money. Our solution is a free solution for the regular small business network administrator, who doesn’t always have the money to spend.
The Technical Details to Send Emails from Command Line?
Our solution used 7zip as a compression utility and Blat as the emailing utility.
7zip is an open-source file archiver. It has a graphical interface but we only used the command line. You can download 7zip here: http://www.7-zip.org/.
Blat is a free, small application, without a graphical interface, that can send email message from the command line. You can download Blat here: http://www.blat.net/.
Following is a batch file example to help you start your own.
:: courtesy of http://dorianblog.info
:: The paths to the report files and the Output folder for the archived file.
:: Insert the date into a variable to use it as a file name
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
:: The recipient list
:: Delete any previously created file
del /q /f "C:\Base-Folder\%Filetosend%.zip"
:: We check if we are connected to the share. ctrl.txt is a dummy file created only for this.
:: It is wise to use a specially created user that only has access to the share. The password of this user is stored on this batch file.
:: We need this in order to make sure the scheduled task runs successfully even if we are not logged in.
if exist "%InputPath%\ctrl.txt" goto auto
net use "%InputPath%" /user:shareUser share-password
:: First compress the file to send using maximum compression. -mx can be lower for reducing the compression time.
C:\Base-Folder\7za a -y -tzip -mx=9 -r %OutputPath%\%date%-%Filetosend%.zip %InputPath%\%Filetosend%.xls
:: If you have winzip installed and you have the command line you can use this.
"C:\Program Files\WinZip\WZZIP.EXE" -a "%OutputPath%\%date%-%Filetosend%.zip" "%InputPath%\%Filetosend%.xls"
:: We send the file now using blat. We use the submit port on our SMTP server and authentication.
:: The authenticated user is "emailuseraccount" with the password "email-password".
:: The variable %RecipientList% contains all of your recipients separated by comas.
blat -server "mail.some-domain.com" -port 587 -u emailUseraccount -pw email-password -f email@example.com -noh -to %RecipientList% -subject "Reports %Filetosend%" -body "Attached you will find your Jet Report" -attach "%OutputPath%\%date%-%Filetosend%.zip"
:: We disconnect the network
net use /delete %InputPath%
:: Remove all the variables
If you found this article useful, post a link to this page or make a comment. You can also comment with improvements of the batch.
If you are looking at a way to automatically send emails through Outlook, there is a limited function of this. The function is limited to composing emails only and they cannot be automatically sent using command line switches. The following command: “C:\Program Files\Microsoft Office\Office11\Outlook.exe” /m “firstname.lastname@example.org” /a “c:\Somefile.zip”
will create a message addressed to email@example.com with the somefile.zip as an attachment. The message will have to be manually sent by an operator. An alternative for a fully automated solution is to use a key stroke simulator such as SendKeys to emulate CTRL+S, (send). Another solution to automatically send emails from Outlook is to use TASK SCHEDULER to call a VBS script. The VBS script does the sending through Outlook. There are a few ways to do this using the Outlook Object Model, or MAPI Mail, or CDO mail. But this is out of the scope of this article and I see very little advantage in developing a VBS script for Outlook.