Пример #1
0
int main(

  int argc,
  char *argv[])

  {
  int amt;
  int err = 0;
  int f;
  int fp;
  int no_attributes = 0;
  job xjob;

  extern int optind;

  while ((f = getopt(argc, argv, "a")) != EOF)
    {
    switch (f)
      {

      case 'a':

        no_attributes = 1;

        break;

      default:

        err = 1;

        break;
      }
    }

  if (err || (argc - optind < 1))
    {
    fprintf(stderr, "usage: %s [-a] file[ file]...}\n",
            argv[0]);

    return(1);
    }

  for (f = optind;f < argc;++f)
    {
    fp = open(argv[f], O_RDONLY, 0);

    if (fp < 0)
      {
      perror("open failed");

      fprintf(stderr, "unable to open file %s\n",
              argv[f]);

      exit(1);
      }

    amt = read_ac_socket(fp, &xjob.ji_qs, sizeof(xjob.ji_qs));

    if (amt != sizeof(xjob.ji_qs))
      {
      fprintf(stderr, "Short read of %d bytes, file %s\n",
              amt,
              argv[f]);
      }

    if (xjob.ji_qs.qs_version != PBS_QS_VERSION)
      {
      printf("%s contains an old version of the ji_qs structure.\n"
             "  expecting version %#010x, read %#010x\n"
             "  Skipping prt_job_struct()\n"
             "  pbs_server may be able to upgrade job automatically\n",
             argv[f], PBS_QS_VERSION, xjob.ji_qs.qs_version);
      close(fp);
      continue;
      }

    /* print out job structure */

    prt_job_struct(&xjob);

    /* now do attributes, one at a time */

    if (no_attributes == 0)
      {
      printf("--attributes--\n");

      while (read_attr(fp))
        /* NO-OP, reading */;
      }

    if (xjob.ji_qs.ji_un_type == JOB_UNION_TYPE_MOM)
      {
      printf("--TM info--\n");

      read_tm_info(fp);
      }

    close(fp);

    printf("\n");
    }  /* END for (f) */

  return(0);
  }    /* END main() */
Пример #2
0
/**
 * @brief
 * 		enable db lookup only for server version of printjob
 *
 * @param[in]	id	-	Job Id.
 * @param[in]	no_attributes	-	if set means no need to set attr_info
 *
 * @return	int
 */
int
print_db_job(char *id, int no_attributes)
{
	pbs_db_obj_info_t obj;
	pbs_db_job_info_t dbjob;
	pbs_db_jobscr_info_t jobscr;
	job xjob;
	int db_conn_error;
	pbs_db_attr_info_t *attrs;
	char *db_errmsg = NULL;
	char errmsg[PBS_MAX_DB_CONN_INIT_ERR + 1];


	if (conn == NULL) {

		/* connect to database */
#ifdef NAS /* localmod 111 */
		if (pbs_conf.pbs_data_service_host) {
			conn = pbs_db_init_connection(pbs_conf.pbs_data_service_host, PBS_DB_CNT_TIMEOUT_NORMAL, 0, &db_conn_error, errmsg, PBS_MAX_DB_CONN_INIT_ERR);
		}
		else
#endif /* localmod 111 */
		conn = pbs_db_init_connection(pbs_conf.pbs_server_name, PBS_DB_CNT_TIMEOUT_NORMAL, 0, &db_conn_error, errmsg, PBS_MAX_DB_CONN_INIT_ERR);
		if (!conn) {
			get_db_errmsg(db_conn_error, &db_errmsg);
			fprintf(stderr, "%s\n", db_errmsg);
			if (strlen(errmsg) > 0)
				fprintf(stderr, "%s\n", errmsg);
			return -1;
		}
		db_conn_error = pbs_db_connect(conn);
		if (db_conn_error != PBS_DB_SUCCESS && pbs_conf.pbs_secondary != NULL) {
			conn = pbs_db_init_connection(pbs_conf.pbs_secondary, PBS_DB_CNT_TIMEOUT_NORMAL, 0, &db_conn_error, errmsg, PBS_MAX_DB_CONN_INIT_ERR);
			if (!conn) {
				get_db_errmsg(db_conn_error, &db_errmsg);
				fprintf(stderr, "%s\n", db_errmsg);
				if (strlen(errmsg) > 0)
					fprintf(stderr, "%s\n", errmsg);
				return -1;
			}
			db_conn_error = pbs_db_connect(conn);
		}
		if (db_conn_error != PBS_DB_SUCCESS) {
			get_db_errmsg(db_conn_error, &db_errmsg);
			fprintf(stderr,
				"Could not connect to PBS dataservice:[%s]\n",
				(db_errmsg)?db_errmsg:"None");
			exit(1);
		}
		if (pg_db_prepare_job_sqls(conn) != 0) {
			get_db_errmsg(db_conn_error, &db_errmsg);
			fprintf(stderr,
				"Could not initialize PBS dataservice:[%s]\n",
				(conn->conn_db_err)?(char *)conn->conn_db_err:"None");
			exit(1);
		}
	}

	/*
	 * On a server machine, if display_script is set,
	 * retrieve the job-script from database.
	 */
	if (display_script) {
		obj.pbs_db_obj_type = PBS_DB_JOBSCR;
		obj.pbs_db_un.pbs_db_jobscr = &jobscr;
		strcpy(jobscr.ji_jobid, id);
		if (strchr(id, '.') == 0) {
			strcat(jobscr.ji_jobid, ".");
			strcat(jobscr.ji_jobid, pbs_conf.pbs_server_name);
		}

		if (pbs_db_load_obj(conn, &obj) != 0) {
			fprintf(stderr, "Job %s not found\n", jobscr.ji_jobid);
			return (1);
		}
		else {
			printf("---------------------------------------------------\n");
			printf("Jobscript for jobid:%s\n", jobscr.ji_jobid);
			printf("---------------------------------------------------\n");

			printf("%s \n", jobscr.script);
		}
	}

	/*
	 * On a server machine, if display_script is not set,
	 * retrieve the job info from database.
	 */
	else {
		obj.pbs_db_obj_type = PBS_DB_JOB;
		obj.pbs_db_un.pbs_db_job = &dbjob;
		strcpy(dbjob.ji_jobid, id);
		if (strchr(id, '.') == 0) {
			strcat(dbjob.ji_jobid, ".");
			strcat(dbjob.ji_jobid, pbs_conf.pbs_server_name);
		}

		if (pbs_db_load_obj(conn, &obj) !=0) {
			fprintf(stderr, "Job %s not found\n", dbjob.ji_jobid);
			return (1);
		}
		db_to_svr_job(&xjob, &dbjob);
		prt_job_struct(&xjob);

		attrs = dbjob.attr_list.attributes;
		if (no_attributes == 0) {
			int i;
			printf("--attributes--\n");
			for (i=0; i< dbjob.attr_list.attr_count; i++) {
				printf("%s", attrs[i].attr_name);
				if (attrs[i].attr_resc && attrs[i].attr_resc[0] != 0)
					printf(".%s", attrs[i].attr_resc);
				printf(" = ");
				if (attrs[i].attr_value)
					printf("%s", show_nonprint_chars(attrs[i].attr_value));
				printf("\n");
			}

		}
		printf("\n");
	}

	return 0;
}