Linux에서 login한 모든 사용자에게 메시지 보내기?
글쓴이: cnyld / 작성시간: 목, 2005/02/17 - 3:32오후
현재 login되어 있는 사용자들에게 메시지를 보내고 싶습니다.
그 사용자들의 telnet 화면에 string이 찍히면 되는데요,
물론 wall 프로그램을 사용하면 되겠지만,
외부 프로그램을 사용하지 않고,
직접 코딩하려고 하거든요.
그니까, 저는 wall_msg()라는 함수를 만들고 싶은거죠.
int wall_msg( char *str, int length )
{
// 모든 사용자에게 str에서 length만큼의 message를 보낸다.
}이 함수를 어떻게 짜야 될까요??Forums:


먼저 tty에 write할 수 있는 권한을 얻은 후 /dev/pts 에
먼저 tty에 write할 수 있는 권한을 얻은 후 /dev/pts 에 있는 모든 파일에 fprintf로 밀어넣으면 될것 같은데요? (vc로 로그인한 사람한테는 힘들겠군요.)
----
데스크탑 프로그래머를 꿈꾸는 임베디드 삽질러
wall 소스를 보시면 되지 않나요?
wall 소스를 보시면 되지 않나요?
--
익스펙토 페트로눔
[quote]wall 소스를 보시면 되지 않나요?[/quote]봐
봐도 잘 모르겠어서 말이죠...
int wall_msg( char *str, int length )
int wall_msg( char *str, int length )
{
char buf[256];
sprintf(buf, "wall %s", str);
system(buf);
}
[quote="..."]int wall_msg( char *str, in
질문자분께서는 wall을 이용하지 않는 방법을 요구하고 계신듯 한데요... :roll:
[quote="cnyld"][quote]wall 소스를 보시면 되지 않나
이해될 때까지 보지 않으셔서 그렇습니다..
wall과 유사한 작은 프로그램을 찾아보시는 것은 어떨까요? Freshmeat에서 찾아보셔도 좋습니다.
[code:1]#include <stdio.h>#inc
#include <stdio.h> #include <utmp.h> int main(int argc, char *argv[]) { struct utmp *entry=NULL; char message_line[1024], terminal_pass[1024]; char my_login_id[1024], other_login_id[1024]; FILE *other_terminal=NULL; int i; memset(message_line, '\0', 1024); printf("전체 메세지를 입력해 주세요.\n"); fgets(message_line, 1024, stdin); strcpy(my_login_id, (char*)getlogin()); setutent(); for(i=0; entry=getutent(); i++) { if (entry==NULL) break; if (entry->ut_type!=USER_PROCESS || entry->ut_user[0]==0) continue; memset(other_login_id, '\0', 1024); strcpy(terminal_pass, "/dev/"); strcat(terminal_pass, entry->ut_line); strcpy(other_login_id, entry->ut_name); other_terminal=fopen(terminal_pass, "w"); if (other_terminal==NULL) { printf("%s님에게 메세지 전달 실패\n", other_login_id); continue; } if (strcmp(other_login_id, my_login_id)==0) continue; fwrite(message_line, 1024, 1, other_terminal); printf("%s님에게 메세지 전달 성공\n", other_login_id); fclose(other_terminal); } endutent(); return 0; }음. 이렇게 전부 다 올려드려두 되는건가 모르겠네요 ;;
예전에 친구가 학교 숙제라며 부탁 하길래, 구글신에 여쭈어 둔 소스입니다.
댓글 달기