Linux에서 login한 모든 사용자에게 메시지 보내기?

cnyld의 이미지

현재 login되어 있는 사용자들에게 메시지를 보내고 싶습니다.
그 사용자들의 telnet 화면에 string이 찍히면 되는데요,
물론 wall 프로그램을 사용하면 되겠지만,

외부 프로그램을 사용하지 않고,
직접 코딩하려고 하거든요.

그니까, 저는 wall_msg()라는 함수를 만들고 싶은거죠.

int wall_msg( char *str, int length )
{
   // 모든 사용자에게 str에서 length만큼의 message를 보낸다.
}
이 함수를 어떻게 짜야 될까요??
ganadist의 이미지

먼저 tty에 write할 수 있는 권한을 얻은 후 /dev/pts 에 있는 모든 파일에 fprintf로 밀어넣으면 될것 같은데요? (vc로 로그인한 사람한테는 힘들겠군요.)

----
데스크탑 프로그래머를 꿈꾸는 임베디드 삽질러

cjh의 이미지

wall 소스를 보시면 되지 않나요?

--
익스펙토 페트로눔

cnyld의 이미지

Quote:
wall 소스를 보시면 되지 않나요?

봐도 잘 모르겠어서 말이죠...

익명 사용자의 이미지

int wall_msg( char *str, int length )
{
char buf[256];
sprintf(buf, "wall %s", str);
system(buf);
}

익명 사용자의 이미지

... wrote:
int wall_msg( char *str, int length )
{
char buf[256];
sprintf(buf, "wall %s", str);
system(buf);
}

질문자분께서는 wall을 이용하지 않는 방법을 요구하고 계신듯 한데요... :roll:

익명 사용자의 이미지

cnyld wrote:
Quote:
wall 소스를 보시면 되지 않나요?

봐도 잘 모르겠어서 말이죠...


이해될 때까지 보지 않으셔서 그렇습니다..

wall과 유사한 작은 프로그램을 찾아보시는 것은 어떨까요? Freshmeat에서 찾아보셔도 좋습니다.

lunarainbow의 이미지

#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;
}

음. 이렇게 전부 다 올려드려두 되는건가 모르겠네요 ;;

예전에 친구가 학교 숙제라며 부탁 하길래, 구글신에 여쭈어 둔 소스입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.