BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aditi24
Obsidian | Level 7

Hi,

 

I am authenticating to the UNIX server using the below statements:-

 

proc printto log='C:\Temp\sastest.log' new;
run;
%let remote=lwstv21.__8015; signon remote=&remote cscript='C:\Script\tcpunix93.scr';
data _null_;
time_slept=sleep(20,1); 
tday=today();
current=time();
put 'Execution time : ' current=time. tday date9. ;
run;
signoff;
proc printto;
run;

My userid and password details are already in the tcpunix93.scr file and this script has been automated. 

But I need to make some changes in the code such that if the signon fails it retries signing on 2 more times . I dont want to read the log file everytime since it will bring much overhead to the code. Please suggest me a way to achieve this requirement.Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

An alternative to @Kurt_Bremser's approach could be using macro and using the RLINK function (untested):

 

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 0;
%let I = 0;
%do %until(&I = &repeat or &rc ne 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr';

data _null_;
  remote_session = optgetc(“&remote”);
  Msg = sysmsg();
  put msg =  remote_session =;
  rc=rlink(remote_session);
  if rc = 0 then put 'No link exists.';
  else put 'A link exists.';
  call symputx(‘rc’, put(rc,2.));
run;
%end;
%mend repeat_signon;

%repeat_signon (remote =%str(lwstv21.__8015));

 

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

The best place to do this is the .scr file that controls the logon process (C:\Script\tcpunix93.scr in your case). The syntax for this file is described in the SAS/CONNECT documentation.

 

You will have to manually replay the logon process with telnet so you can see the responses you get from the remote server; you can then code corresponding reactions into the .scr file.

I did that to catch the "password expired" message delivered by AIX and consequently prompt the user for a new password.

SASKiwi
PROC Star

An alternative to @Kurt_Bremser's approach could be using macro and using the RLINK function (untested):

 

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 0;
%let I = 0;
%do %until(&I = &repeat or &rc ne 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr';

data _null_;
  remote_session = optgetc(“&remote”);
  Msg = sysmsg();
  put msg =  remote_session =;
  rc=rlink(remote_session);
  if rc = 0 then put 'No link exists.';
  else put 'A link exists.';
  call symputx(‘rc’, put(rc,2.));
run;
%end;
%mend repeat_signon;

%repeat_signon (remote =%str(lwstv21.__8015));

 

Aditi24
Obsidian | Level 7

Hi @SASKiwi,

 

The code is giving below error:-

 

68
ERROR 68-185: The function OPTGETC is unknown, or cannot be accessed.

2883 Msg = sysmsg();
2884 put msg = remote_session =;
2885 rc= rlink(remote_session);
-----
68
ERROR 68-185: The function RLINK is unknown, or cannot be accessed.

2886 if rc = 0 then put 'No link exists.';
2887 else put 'A link exists.';
2888 call symputx('rc', put(rc,2.));
2889 run;

 

SASKiwi
PROC Star

Sorry, most SCL functions work in the DATA step but obviously not that one. Perhaps try @BrunoMueller's suggestion in the same macro:

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 99;
%let I = 0;
%do %until(&I = &repeat or &rc = 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr' CMACVAR = signonrc;
%let rc = &signonrc;
data _null_; remote_session = optgetc(“&remote”); Msg = sysmsg(); put msg = remote_session =; if symget('rc') = 0 then put 'A link exists.'; else put 'A link does not exist.'; run; %end;
%mend repeat_signon; %repeat_signon (remote =%str(lwstv21.__8015));

 

Kurt_Bremser
Super User

The rlink() function is only present in SCL, so it won't be of much help outside a DMS SAS. An one would need to have SAS/AF licensed to build a SCL program.

Aditi24
Obsidian | Level 7
Thanks @SASKiwi, you are a saviour.
BrunoMueller
SAS Super FREQ

Hi

 

Check the doc for SIGNON Statement and Command. The SIGNON statement provides the CMACVAR option to name a macro variable that will tell you the follwoing:

 

CMACVAR Macro Variable Values in SIGNON
Value
Description
0
The sign-on is complete.
1
The sign-on failed.
2
You have already signed on to the current server session.
3
The sign-on is in progress.
Note: If the SIGNON command or statement fails because of incorrect syntax, the macro variable is not set.
 
Bruno

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
  • 8 replies
  • 1515 views
  • 3 likes
  • 4 in conversation