1.\" -*- nroff -*- 2.\" manual page [] for chat 1.8 3.\" $FreeBSD: src/usr.bin/chat/chat.8,v 1.15.2.3 2003/02/24 22:37:41 trhodes Exp $ 4.\" $DragonFly: src/usr.bin/chat/chat.8,v 1.7 2008/05/09 20:31:04 swildner Exp $ 5.Dd September 27, 1996 6.Dt CHAT 8 7.Os 8.Sh NAME 9.Nm chat 10.Nd Automated conversational script with a modem 11.Sh SYNOPSIS 12.Nm 13.Op Fl evVsS 14.Op Fl f Ar chat_file 15.Op Fl r Ar report_file 16.Op Fl t Ar timeout 17.Op Fl T Ar phone_number 18.Op Fl U Ar phone_number 19.Sh DESCRIPTION 20The 21.Nm 22program defines a conversational exchange between the computer and the modem. 23Its primary purpose is to establish the 24connection between the Point-to-Point Protocol Daemon 25.Xr ( pppd 8 ) 26and the remote's 27.Xr pppd 8 28process. 29.Sh OPTIONS 30The following options are provided: 31.Bl -tag -width ".Fl U Ar phone_number" -offset indent 32.It Fl f Ar chat_file 33Read the chat script from 34.Ar chat_file . 35The use of this option is mutually exclusive with the chat script parameters. 36The user must have read access to the file. 37Multiple lines are permitted in the file. 38Space or horizontal tab characters should be used to separate the strings. 39.It Fl t Ar timeout 40Set the timeout for the expected string to be received. 41If the string 42is not received within the time limit then the reply string is not sent. 43An alternate reply may be sent or the script will fail if there 44is no alternate reply string. 45A failed script will cause the 46.Nm 47program to terminate with a non-zero error code. 48.It Fl r Ar report_file 49Set the file for output of the report strings. 50If you use the keyword 51.Dq REPORT , 52the resulting strings are written to this file. 53If this option is not used and you still use 54.Dq REPORT 55keywords, the stderr file is used for the report strings. 56.It Fl e 57Start with the echo option turned on. 58Echoing may also be turned on 59or off at specific points in the chat script by using the 60.Dq ECHO 61keyword. 62When echoing is enabled, all output from the modem is echoed to stderr. 63.It Fl v 64Request that the 65.Ar script 66be executed in a verbose mode. 67The 68.Nm 69program will then log the execution state of the chat 70script as well as all text received from the modem and the output 71strings sent to the modem. 72The default is to log through 73.Xr syslog 3 ; 74the logging method may be altered with the 75.Fl S 76and 77.Fl s 78flags. 79Logging is done to the 80.Dq local2 81facility at level 82.Dq info 83for verbose tracing and level 84.Dq err 85for some errors. 86.It Fl V 87Request that 88.Ar script 89be executed in a stderr verbose mode. 90The 91.Nm 92program will then log all text received from the 93modem and the output strings sent to the modem to the stderr device. 94This 95device is usually the local console at the station running the chat or 96pppd program. 97.It Fl s 98Use stderr. 99All log messages from 100.Fl v 101and all error messages will be sent to stderr. 102.It Fl S 103Do not use 104.Xr syslog 3 . 105By default, error messages are sent to 106.Xr syslog 3 . 107The use of 108.Fl S 109will prevent both log messages from 110.Fl v 111and error messages from being sent to 112.Xr syslog 3 . 113.It Fl T Ar phone_number 114Pass in an arbitrary string, usually a phone number, that will be 115substituted for the \eT substitution metacharacter in a send string. 116.It Fl U Ar phone_number 117Pass in a second string, usually a phone number, that will be 118substituted for the \eU substitution metacharacter in a send string. 119This is useful when dialing an ISDN terminal adapter that requires two 120numbers. 121.It Ar script 122If the script is not specified in a file with the 123.Fl f 124option then the script is included as parameters to the 125.Nm 126program. 127.El 128.Sh CHAT SCRIPT 129The 130.Nm 131script defines the communications. 132.Pp 133A script consists of one or more 134.Dq expect-send 135pairs of strings, separated by spaces, with an optional 136.Dq subexpect-subsend 137string pair, separated by a dash as in the following example: 138.Pp 139.Dl ogin:-BREAK-ogin: ppp ssword: hello2u2 140.Pp 141This line indicates that the 142.Nm 143program should expect the string 144.Dq ogin: . 145If it fails to receive a login prompt within the time interval 146allotted, it is to send a break sequence to the remote and then expect the 147string 148.Dq ogin: . 149If the first 150.Dq ogin: 151is received then the break sequence is not generated. 152.Pp 153Once it received the login prompt the 154.Nm 155program will send the string ppp and then expect the prompt 156.Dq ssword: . 157When it receives the 158prompt for the password, it will send the password hello2u2. 159.Pp 160A carriage return is normally sent following the reply string. 161It is not expected in the 162.Dq expect 163string unless it is specifically requested by using the \er character sequence. 164.Pp 165The expect sequence should contain only what is needed to identify the string. 166Since it is normally stored on a disk file, it should not contain 167variable information. 168It is generally not acceptable to look for time 169strings, network identification strings, or other variable pieces of data as 170an expect string. 171.Pp 172To help correct for characters which may be corrupted during the initial 173sequence, look for the string 174.Dq ogin: 175rather than 176.Dq login: . 177It is possible that the leading 178.Dq l 179character may be received in error and you may never 180find the string even though it was sent by the system. 181For this reason, scripts look for 182.Dq ogin: 183rather than 184.Dq login: 185and 186.Dq ssword: 187rather than 188.Dq password: . 189.Pp 190A very simple script might look like this: 191.Pp 192.Dl ogin: ppp ssword: hello2u2 193.Pp 194In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2. 195.Pp 196In actual practice, simple scripts are rare. 197At the vary least, you 198should include sub-expect sequences should the original string not be 199received. 200For example, consider the following script: 201.Pp 202.Dl ogin:--ogin: ppp ssword: hello2u2 203.Pp 204This would be a better script than the simple one used earlier. 205This would look 206for the same login: prompt, however, if one was not received, a single 207return sequence is sent and then it will look for login: again. 208Should line 209noise obscure the first login prompt then sending the empty line will 210usually generate a login prompt again. 211.Sh COMMENTS 212Comments can be embedded in the chat script. 213A comment is a line which 214starts with the 215.Sy # 216(hash) character in column 1. 217Such comment lines are just ignored by the chat program. 218If a 219.Sq # 220character is to 221be expected as the first character of the expect sequence, you should 222quote the expect string. 223If you want to wait for a prompt that starts with a # (hash) 224character, you would have to write something like this: 225.Bd -literal -offset indent 226# Now wait for the prompt and send logout string 227.br 228\&'# ' logout 229.Ed 230.Sh ABORT STRINGS 231Many modems will report the status of the call as a string. 232These strings may be 233.Dq CONNECTED 234or 235.Dq NO CARRIER 236or 237.Dq BUSY . 238It is often desirable to terminate the script should the modem fail to 239connect to the remote. 240The difficulty is that a script would not know 241exactly which modem string it may receive. 242On one attempt, it may receive 243.Dq BUSY 244while the next time it may receive 245.Dq NO CARRIER . 246.Pp 247These 248.Dq abort 249strings may be specified in the script using the 250.Dq ABORT 251sequence. 252It is written in the script as in the following example: 253.Pp 254.Dl ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT 255.Pp 256This sequence will expect nothing; and then send the string ATZ. 257The expected response to this is the string 258.Dq OK . 259When it receives 260.Dq OK , 261the string ATDT5551212 to dial the telephone. 262The expected string is 263.Dq CONNECT . 264If the string 265.Dq CONNECT 266is received the remainder of the script is executed. 267However, should the modem find a busy telephone, it will send the string 268.Dq BUSY . 269This will cause the string to match the abort character sequence. 270The script will then fail because it found a match to the abort string. 271If it received the string 272.Dq NO CARRIER , 273it will abort for the same reason. 274Either string may be received. 275Either string will terminate the 276.Nm 277script. 278.Sh CLR_ABORT STRINGS 279This sequence allows for clearing previously set 280.Dq ABORT 281strings. 282.Dq ABORT 283strings are kept in an array of a pre-determined size (at compilation time); 284.Dq CLR_ABORT will reclaim the space for cleared 285entries so that new strings can use that space. 286.Sh SAY STRINGS 287The 288.Dq SAY 289directive allows the script to send strings to the user 290at the terminal via standard error. 291If 292.Nm 293is being run by 294pppd, and pppd is running as a daemon (detached from its controlling 295terminal), standard error will normally be redirected to the file 296.Pa /etc/ppp/connect-errors . 297.Pp 298.Dq SAY 299strings must be enclosed in single or double quotes. 300If carriage return and line feed are needed in the string to be output, 301you must explicitly add them to your string. 302.Pp 303The 304.Dq SAY 305strings could be used to give progress messages in sections of 306the script where you want to have 307.Sq ECHO OFF 308but still let the user know what is happening. 309An example is: 310.Bd -literal -offset indent 311ABORT BUSY 312ECHO OFF 313SAY "Dialling your ISP...\\n" 314.br 315\&'' ATDT5551212 316TIMEOUT 120 317SAY "Waiting up to 2 min. for connection... " 318CONNECT '' 319SAY "Connected, now logging in...\\n" 320ogin: account 321ssword: pass 322$ \c 323SAY "Logged in OK ...\\n" 324\&... 325.Ed 326.Pp 327This sequence will only present the SAY strings to the user and all 328the details of the script will remain hidden. 329For example, if the above script works, the user will see: 330.Bd -literal -offset indent 331Dialling your ISP... 332Waiting up to 2 min. for connection... Connected, now logging in... 333Logged in OK ... 334.Ed 335.Sh REPORT STRINGS 336A 337.Dq report 338string is similar to the ABORT string. 339The difference 340is that the strings, and all characters to the next control character 341such as a carriage return, are written to the report file. 342.Pp 343The report strings may be used to isolate the transmission rate of the 344modem's connect string and return the value to the chat user. 345The analysis of the report string logic occurs in conjunction with the 346other string processing such as looking for the expect string. 347The use of the same string for a report and abort sequence is probably not 348very useful, however, it is possible. 349.Pp 350The report strings to no change the completion code of the program. 351.Pp 352These 353.Dq report 354strings may be specified in the script using the 355.Dq REPORT 356sequence. 357It is written in the script as in the following example: 358.Pp 359.Dl REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account 360.Pp 361This sequence will expect nothing; and then send the string 362ATDT5551212 to dial the telephone. 363The expected string is 364.Dq CONNECT . 365If the string 366.Dq CONNECT 367is received the remainder of the script is executed. 368In addition the program will write to the expect-file the string 369.Dq CONNECT 370plus any characters which follow it such as the connection rate. 371.Sh CLR_REPORT STRINGS 372This sequence allows for clearing previously set 373.Dq REPORT 374strings. 375.Dq REPORT 376strings are kept in an array of a pre-determined size (at compilation time); 377.Dq CLR_REPORT 378will reclaim the space for cleared 379entries so that new strings can use that space. 380.Sh ECHO 381The echo options controls whether the output from the modem is echoed 382to stderr. 383This option may be set with the 384.Fl e 385option, but it can also be controlled by the 386.Dq ECHO 387keyword. 388The 389.Dq expect-send 390pair 391.Dq ECHO ON 392enables echoing, and 393.Dq ECHO OFF 394disables it. 395With this keyword you can select which parts of the 396conversation should be visible. 397For instance, with the following script: 398.Bd -literal -offset indent 399ABORT 'BUSY' 400ABORT 'NO CARRIER' 401.br 402\&'' ATZ 403OK\\r\\n ATD1234567 404\\r\\n \\c 405ECHO ON 406CONNECT \\c 407ogin: account 408.Ed 409.Pp 410all output resulting from modem configuration and dialing is not visible, 411but starting with the 412.Dq CONNECT 413(or 414.Dq BUSY ) 415message, everything will be echoed. 416.Sh HANGUP 417The HANGUP options control whether a modem hangup should be considered 418as an error or not. This option is useful in scripts for dialling 419systems which will hang up and call your system back. The HANGUP 420options can be 421.Dq ON 422or 423.Dq OFF . 424.Pp 425When HANGUP is set OFF and the modem hangs up (e.g., after the first 426stage of logging in to a callback system), 427.Nm 428will continue 429running the script (e.g.\&, waiting for the incoming call and second 430stage login prompt). As soon as the incoming call is connected, you 431should use the 432.Dq HANGUP ON 433directive to reinstall normal hang up signal behavior. 434Here is a (simple) example script: 435.Bd -literal -offset indent 436ABORT 'BUSY' 437.br 438\&'' ATZ 439OK\\r\\n ATD1234567 440\\r\\n \\c 441CONNECT \\c 442.br 443\&'Callback login:' call_back_ID 444HANGUP OFF 445ABORT "Bad Login" 446.br 447\&'Callback Password:' Call_back_password 448TIMEOUT 120 449CONNECT \\c 450HANGUP ON 451ABORT "NO CARRIER" 452ogin:--BREAK--ogin: real_account 453\&... 454.Ed 455.Sh TIMEOUT 456The initial timeout value is 45 seconds. 457This may be changed using the 458.Fl t 459parameter. 460.Pp 461To change the timeout value for the next expect string, the following 462example may be used: 463.Pp 464.Dl ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2 465.Pp 466This will change the timeout to 10 seconds when it expects the login: 467prompt. 468The timeout is then changed to 5 seconds when it looks for the 469password prompt. 470.Pp 471The timeout, once changed, remains in effect until it is changed again. 472.Sh SENDING EOT 473The special reply string of 474.Dq EOT 475indicates that the chat program should send an EOT character to the remote. 476This is normally the End-of-file character sequence. 477A return character is not sent following the EOT. 478.Pp 479The EOT sequence may be embedded into the send string using the 480sequence 481.Dq ^D . 482.Sh GENERATING BREAK 483The special reply string of 484.Dq BREAK 485will cause a break condition to be sent. 486The break is a special signal on the transmitter. 487The normal processing on the receiver is to change the transmission rate. 488It may be used to cycle through the available transmission rates on 489the remote until you are able to receive a valid login prompt. 490.Pp 491The break sequence may be embedded into the send string using the 492.Dq \eK 493sequence. 494.Sh ESCAPE SEQUENCES 495The expect and reply strings may contain escape sequences. 496All of the sequences are legal in the reply string. 497Many are legal in the expect. 498Those which are not valid in the expect sequence are so indicated. 499.Bl -tag -width ".Li \e\e000" 500.It Li '' 501Expects or sends a null string. 502If you send a null string then it will still send the return character. 503This sequence may either be a pair of apostrophe or quote characters. 504.It Li \eb 505represents a backspace character. 506.It Li \ec 507Suppresses the newline at the end of the reply string. 508This is the only method to send a string without a trailing return character. 509It must be at the end of the send string. 510For example, 511the sequence hello\ec will simply send the characters h, e, l, l, o. 512.Em ( not valid in expect . ) 513.It Li \ed 514Delay for one second. 515The program uses 516.Xr sleep 1 517which will delay to a maximum of one second. 518.Em ( not valid in expect . ) 519.It Li \eK 520Insert a BREAK 521.Em ( not valid in expect . ) 522.It Li \en 523Send a newline or linefeed character. 524.It Li \eN 525Send a null character. 526The same sequence may be represented by \e0. 527.Em ( not valid in expect . ) 528.It Li \ep 529Pause for a fraction of a second. 530The delay is 1/10th of a second. 531.Em ( not valid in expect . ) 532.It Li \eq 533Suppress writing the string to 534.Xr syslogd 8 . 535The string ?????? is 536written to the log in its place. 537.Em ( not valid in expect . ) 538.It Li \er 539Send or expect a carriage return. 540.It Li \es 541Represents a space character in the string. 542This may be used when it 543is not desirable to quote the strings which contains spaces. 544The sequence 545.Sq HI TIM 546and 547.Sq HI\esTIM 548are the same. 549.It Li \et 550Send or expect a tab character. 551.It Li \e\e 552Send or expect a backslash character. 553.It Li \e\eddd 554Collapse the octal digits (ddd) into a single ASCII character and send that 555character. 556.Em ( some characters are not valid in expect . ) 557.It Li ^C 558Substitute the sequence with the control character represented by C. 559For example, the character DC1 (17) is shown as ^Q. 560.Em ( some characters are not valid in expect . ) 561.El 562.Sh TERMINATION CODES 563The 564.Nm 565program will terminate with the following completion codes. 566.Bl -tag -width ".Li ..." 567.It Li 0 568The normal termination of the program. 569This indicates that the script 570was executed without error to the normal conclusion. 571.It Li 1 572One or more of the parameters are invalid or an expect string was too 573large for the internal buffers. 574This indicates that the program as not properly executed. 575.It Li 2 576An error occurred during the execution of the program. 577This may be due 578to a read or write operation failing for some reason or chat receiving 579a signal such as 580.Dv SIGINT . 581.It Li 3 582A timeout event occurred when there was an 583.Dq expect 584string without having a 585.Dq -subsend 586string. 587This may mean that you did not program the 588script correctly for the condition or that some unexpected event has 589occurred and the expected string could not be found. 590.It Li 4 591The first string marked as an 592.Dq ABORT 593condition occurred. 594.It Li 5 595The second string marked as an 596.Dq ABORT 597condition occurred. 598.It Li 6 599The third string marked as an 600.Dq ABORT 601condition occurred. 602.It Li 7 603The fourth string marked as an 604.Dq ABORT 605condition occurred. 606.It Li ... 607The other termination codes are also strings marked as an 608.Dq ABORT 609condition. 610.El 611.Pp 612Using the termination code, it is possible to determine which event 613terminated the script. 614It is possible to decide if the string 615.Dq BUSY 616was received from the modem as opposed to 617.Dq NO DIAL TONE . 618While the first event may be retried, the second will probably have little 619chance of succeeding during a retry. 620.Sh SEE ALSO 621.Xr uucico 1 , 622.Xr uucp 1 , 623.Xr syslog 3 , 624.Xr syslogd 8 625.Pp 626Additional information about 627.Nm 628scripts may be found with UUCP documentation. 629The 630.Nm 631script was taken from the ideas proposed by the scripts used by the 632.Xr uucico 1 633program. 634.Sh COPYRIGHT 635The 636.Nm 637program is in public domain. 638This is not the GNU public license. 639If it breaks then you get to keep both pieces. 640