Sponsored Content
Top Forums Programming creation of unwanted directory Post 85365 by mridula on Wednesday 5th of October 2005 02:45:47 AM
Old 10-05-2005
re:

///////// here is the code that i am using to create the directory//////////////
Code:
#include<stdio.h>
#include<stdlib.h>
#include<sys/dir.h> 
#include<malloc.h>
#include<string.h>

struct sconfig *head;
struct sconfig *tail;
struct sconfig
{
	int type,id;
	char username[20], IP[15];
	struct sconfig *next;
};

int dircreate(int id,int type)  //code to create the directory
{
	char *dname;
	int stat;
	dname=(char *)malloc(sizeof(int));
	sprintf(dname,"node_%d",id);
	stat=mkdir(dname,"rwx");
	if(stat!=0)
	{
		printf("\nnode dir cud not b created");
	}
	return 0;
}

int loadlist(int chcount)//code to read s_config.txt	
{
	FILE *fsdt;
	struct sconfig *temp;
	if((fsdt=fopen("/root/sample_read/s_config.txt","r")) == NULL)
	{
		fprintf(stderr, "cannot open s_config.txt\n");
		return 1;
	}
	while(feof(fsdt) == 0)
	{
		temp=(struct sconfig *)malloc(sizeof(struct sconfig));
		fscanf(fsdt,"%d %s %s %d",&temp->id, temp->username, temp->IP, &temp->type);
		dircreate(temp->id,temp->type);
		temp->next='\0';
		if (head==NULL)
		{	   head=temp;   		}
		else
                {         tail->next=temp;		}
		tail=temp;
	}
	fclose(fsdt);
	return 0;
}

int main()
{
	FILE *fsdt;
	int chcount=0;
	char ch;
	fsdt=fopen("/root/sample_read/s_config.txt","r");
	if (fsdt!=NULL)
	{
		while(1)
		{
			ch=fgetc(fsdt);
			if(ch==EOF)
				break;
			else
				chcount=chcount+1;
		}
		fclose(fsdt);
		if(chcount>0)
		{ 		loadlist(chcount);		}
	}
	else
	{
		fprintf(stderr, "cannot open s_config.txt\n");
		return 1;
	}
	return 0;
}

/////////////////////contents of s_config.txt file ////////////////////////

1 bhakti 123.123.123.123 1
2 mridu 255.254.255.254 2
3 ash 11.11.11.11 1
4 ashish 45.23.12.56 2

hope anyone can find the bug

thankx

Last edited by Perderabo; 10-05-2005 at 12:15 PM.. Reason: Add code tags for readability
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Remote directory creation

Is there a way to create a directory in some remote location from a local location? I understand that we can use 'rcp' to copy a local file to a remote location. I am looking for a command in similar lines which lets us create directories in remote locations. Could someone help? (5 Replies)
Discussion started by: srinivay
5 Replies

2. UNIX for Advanced & Expert Users

directory creation

Hi Friends, I am trying to move some files from one directory to another. but if the destination directory doesnt exist then i have to create one and then move files to that. For this i have to write a script. please help. thanks in advance Veera (4 Replies)
Discussion started by: sveera
4 Replies

3. UNIX for Dummies Questions & Answers

Mass directory creation?

I have a couple thousand data files that all have to have there own directory named exactly the same as the file name. Then the file needs to be moved to that directory. For example files test1.mat, test2.mat, test3.mat in directory X need to have directories test1, test2, test3 created... (6 Replies)
Discussion started by: AeroEngy
6 Replies

4. AIX

Filesystem creation over existing Directory

Is it possible to create a Filesystem with the mount point over an existing Directory, without loosing the data in the Directory? eg:- /u01 -> /pmmpd/u01 (Directory with soft link) /pmmpd/u01 (Need to create this filesystem, without loosing data) Thanks TheDoc (0 Replies)
Discussion started by: TheDoc
0 Replies

5. Shell Programming and Scripting

Directory Creation problem

Hiiii, here is my script-- BackupLocation="$OPTARG" if ]; then echo "Either option l or L should be given to $Programname" echo "$Usage" echo "$Programname is terminated" ... (1 Reply)
Discussion started by: namishtiwari
1 Replies

6. Shell Programming and Scripting

Changing file permission upon creation in a directory

I want to change the permission of a file when it gets created in a particular directory. For instance, I have directory MyDir. Everytime a file gets created in that directory, I would like to change the permission to 777. The context is that I have a 3rd party appication running as root. Only... (2 Replies)
Discussion started by: laiko
2 Replies

7. Shell Programming and Scripting

Creation date of a directory

what's the command to find the creation date of a certain dirctory? (1 Reply)
Discussion started by: miss_dodi
1 Replies

8. UNIX for Beginners Questions & Answers

UNIX directory creation issues

Hi All, I am facing a strange scenario. I upgraded my server version to new version of linux. After the when I create a directory it is created with . in the the permission . What is the reason and how to fix . $ mkdir test $ ls -l total 0 drwxr-xr-x. 2 uk01 users 6 Dec 7 03:49 test ... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. Shell Programming and Scripting

Bash directory loop and order by creation date?

Hello, how in bash i can get directory loop and order by creation date? THX! :) #!/bin/bash for folder in /home/test/* do if ; then echo $folder; fi (12 Replies)
Discussion started by: ZerO13
12 Replies

10. Shell Programming and Scripting

Reason for no directory creation date

i read here that linux provides no way to determine when a directory was created. https://www.unix.com/shell-programming-and-scripting/157874-creation-date-directory.htmlI have a directory /home/andy/scripts that had a README file in it. That file says I put the script in that directory and... (3 Replies)
Discussion started by: drew77
3 Replies
LFC_MKDIR(3)						       LFC Library Functions						      LFC_MKDIR(3)

NAME
lfc_mkdir - create a new LFC directory in the name server SYNOPSIS
#include <sys/types.h> #include "lfc_api.h" int lfc_mkdir (const char *path, mode_t mode) DESCRIPTION
lfc_mkdir creates a new LFC directory in the name server. An entry is created in the name server database and the directory's owner ID is set to the effective user ID of the requestor. The group ID of the directory is set to the effective group ID of the requestor or is taken from the parent directory if the latter has the S_ISGID bit set. The access permission bits for the directory are taken from mode, then all bits set in the requestor's file mode creation mask are cleared (see lfc_umask(3)). The S_ISGID, S_ISUID and S_ISVTX bits are silently cleared. path specifies the logical pathname relative to the current LFC directory or the full LFC pathname. RETURN VALUE
This routine returns 0 if the operation was successful or -1 if the operation failed. In the latter case, serrno is set appropriately. ERRORS
ENOENT A component of path prefix does not exist or path is a null pathname. EACCES Search permission is denied on a component of the path prefix or write permission on the parent directory is denied. EFAULT path is a NULL pointer. EEXIST path exists already. ENOTDIR A component of path prefix is not a directory. ENOSPC The name server database is full. ENAMETOOLONG The length of path exceeds CA_MAXPATHLEN or the length of a path component exceeds CA_MAXNAMELEN. SENOSHOST Host unknown. SENOSSERV Service unknown. SECOMERR Communication error. ENSNACT Name server is not running or is being shutdown. SEE ALSO
Castor_limits(4), lfc_chdir(3), lfc_chmod(3), lfc_umask(3) AUTHOR
LCG Grid Deployment Team LFC
$Date: 2001/10/04 12:12:45 $ LFC_MKDIR(3)
All times are GMT -4. The time now is 08:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy