DATA Step, Macro, Functions and more

Need to Send email notification when the disk is 75% full, we are using Unix

Reply
Contributor
Posts: 66

Need to Send email notification when the disk is 75% full, we are using Unix

Hi 

I am trying to Write a SAS code which would trigger an email when the disk size reaches 75%.

Kindly help me on this.

Occasional Contributor
Posts: 18

Re: Need to Send email notification when the disk is 75% full, we are using Unix

Hi,

 

You can use following logic:-

 

By using X command please fire "DF" command on Linux. It will give you details of all drives available on Linux. Pipe these details into a macro variable for your desired drive. If that macro variable is having value more than 75% fire following data step:-

 

  filename outbox email "<Email id to whom email is send>";

  data _null_;    

    file outbox

       subject="Alert!!!!!!  Disk space is 75% occupied"    

    ;    

    put 'Your hard disk is 75% occupied. Please clean unused data.';    

  run;

 

In short over all logic will be:-

 

%macro check_hard_disk_capacity;

 

/*X command to check desired hard disk capacity and take it into macro variable*/

 

%if &macro_varaible > 75 %then %do;

 

 

filename outbox email "<Email id to whom email is send>";

  data _null_;    

    file outbox

       subject="Alert!!!!!!  Disk space is 75% occupied"    

    ;    

    put 'Your hard disk is 75% occupied. Please clean unused data.';    

  run;

 

%end;

%mend;

 

I hope this helps.

 

Regards,

Abd.

Super Contributor
Posts: 426

Re: Need to Send email notification when the disk is 75% full, we are using Unix

Assume /tmp exceeds 75%,  then how will you pipe this details into macro variable?

Super User
Super User
Posts: 7,401

Re: Need to Send email notification when the disk is 75% full, we are using Unix

Speak to your IT group, they will have tools which can monitor drive space on a network and alert users when a drive is filling up.  Don't try to re-invent the wheel on your own.

Occasional Contributor
Posts: 18

Re: Need to Send email notification when the disk is 75% full, we are using Unix

%macro send_email;

	data _null_;
	<X command to get values of disk space. Let us assume that this output is redirected to
	file "out.txt." stored at "<Your location>";
	run;

	data input_data;
		infile "<Your file location>"
			firstobs = 1
			dlm = ":"
			missover
			dsd
			lrecl = 32767;
		input
			Description : $char128. /*string field of 128 chars long*/
		bytes_Occupied : $char128. /*numbers of all types ints, floats, etc */
		;
	run;


	data input_data;
		set input_data;
		Description=tranwrd(compress(Description,''),'#','no');
	run;

	proc sql;
		select bytes_occupied into : free_bytes from input_data where description='Totalnooffreebytes';
		select bytes_occupied into : total_bytes from input_data where description='Totalnoofbytes';
		create table memory_stat 
			(
			Total_no_of_free_bytes char(10000),
			Total_no_of_bytes char(10000)
			);
		insert into memory_stat values("&free_bytes.","&total_bytes.");
	quit;

	data memory_stat(drop=Total_no_of_free_bytes Total_no_of_bytes);
		set memory_stat;
		Total_no_of_free_bytes_num=input(Total_no_of_free_bytes,20.0);
		Total_no_of_bytes_num=input(Total_no_of_bytes,20.0);
		Disk_consumption_in_perctage=(Total_no_of_bytes-Total_no_of_free_bytes)/Total_no_of_bytes*100;
		call symputx("disk_utilization",Disk_consumption_in_perctage);
	run;

	%put &disk_utilization.;

	%if &disk_utilization. >= 75 %then
		%do;
			filename outbox email "<Email id>";

			data _null_;
				file outbox
				subject="Alert!!!!!!  Disk space is 75% occupied"    
				;
				put 'Your hard disk is 75% occupied. Please clean unused data.';
			run;

		%end;
%mend;
%send_email;

Not sure about Unix commnd but using windows command which is giving output as per attached snapshot we can code a mcaro mentioned above. Some calculations has to be done to get a macro parameter.I hope this will help.


Log_File_Windows_Disk_Consumption.JPG
PROC Star
Posts: 392

Re: Need to Send email notification when the disk is 75% full, we are using Unix

If you have a SAS 9.4 platform installation then you may have SAS Environment Manager which can be configured to montitor resources such as disk space utilization, and generate alerts with an escalation scheme. Some resources that may be of interest to you if you want to use this approach:

 

Ask a Question
Discussion stats
  • 5 replies
  • 279 views
  • 2 likes
  • 5 in conversation