BookmarkSubscribeRSS Feed
santosh_pat69
Quartz | Level 8

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.

5 REPLIES 5
ad123123
Fluorite | Level 6

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.

Babloo
Rhodochrosite | Level 12

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ad123123
Fluorite | Level 6
%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
PaulHomes
Rhodochrosite | Level 12

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:

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1279 views
  • 2 likes
  • 5 in conversation