Sponsored Content
Top Forums Shell Programming and Scripting Retain file permissions when saving .sh file from internet [OS X] Post 302266869 by baza210 on Thursday 11th of December 2008 08:29:26 AM
Old 12-11-2008
Retain file permissions when saving .sh file from internet [OS X]

Hello.
I have written a bash script that I am sharing with an OS X community I am a member of. The purpose of the script is to execute a series of commands for members without them having to get involved with Terminal, as it can be daunting for those with no experience of it at all. I have renamed the file from .sh to .command, as this allows you to execute it by double-clicking the file in the OS X file manager.
The file saves itself from my script editor [Smultron] with read and write permission only, and not executable permission; I use chmod 755 {file} to give myself execute permission, and then upload the file using ftp. Connecting to my server with ftp I then find that the file permissions have changed back to read/write, so I again use chmod in the ftp shell and change the permissions again. I thought this would have prevented the following problem, but I guess not-
When I, or anyone else, saves the file from the public domain folder I have hosted it in, the permissions are back to not being executable. Of course, this can be fixed with chmod +x, but that rather defeats the purpose of the script if they have to get involved with Terminal at all.

Could anyone please suggest a way to resolve this issue, ie how can I get the file to have persistent executable permission for all? It's driving me nuts at this stage.. I've put quite a lot of effort into the script.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parse an arpwatch file and retain most recent mac

Hi, I'm working on a little script, for first I transformed epoch (unix date in seconds) in a human readable date in this way cat arp.dat | sort -k 3 | gawk '{ print strftime("%d:%m:%Y:%H:%M", $3),$1,$2}' the result is 06:03:2006:10:01 0:a:e4:c0:b5:6d 192.168.1.3 06:03:2006:12:15... (8 Replies)
Discussion started by: CM64
8 Replies

2. UNIX for Advanced & Expert Users

How to retain file permissions during FTP on Solaris 5.9 ?

Hi All, I am trying to ftp a file : -rw-rw-rw- 1 oraclepbdw dba filename.txt from Machine A ( where umask is 022) to Machine B (umask 022) but the file changes to -rw-rw-r-- 1 ftpamle3 ftaml filename.txt Dur some constraints the group of the users on either side... (3 Replies)
Discussion started by: gauravsachan
3 Replies

3. UNIX for Dummies Questions & Answers

How to retain the header information of a file

Hi, I am using Bash shell to create some data and these data would be piped out to a file, let say output.txt. This output.txt I would like to add some extra header information such as comments, descriptions and general information on the text. I would like to know how could I maintain... (0 Replies)
Discussion started by: ahjiefreak
0 Replies

4. UNIX for Advanced & Expert Users

Retain Only specific number of file in Directory

I want to retain specific number of backup files in a directory.for example i want to retain only two latest backup file in backup directory. If number of backup files is greater than this policy that it will delete oldest file.Please Tell me whether this is possible or not. (2 Replies)
Discussion started by: ranvijaidba
2 Replies

5. Shell Programming and Scripting

Retain File Timestamp

There are directories of files that I have to run the dos2ux command on to get ride of the carriage return characters. Easy enough, but I have to retain the original timestamps on the files. I am thinking that I am going to have to strip off the timestamp for each file and convert it to unix time... (3 Replies)
Discussion started by: scotbuff
3 Replies

6. Shell Programming and Scripting

retain last 1000 line in a file

I have large file with around 100k+ lines. I wanted to retain only the last 100 lines in that file. One way i thought was using tail -1000 filename > filename1 mv filename1 filename But there should be a better solution.. Is there a way I can use sed or any such command to change the... (9 Replies)
Discussion started by: nss280
9 Replies

7. Shell Programming and Scripting

How to retain backslash in a line while reading a data file?

Hello Firends I have a file that contains data within single quotes, which has meaning of its own. When I am trying to parse through the file for a different functionality I noticed that I was loosing the backslash when occurrences in the file look like ('\0'). I would want to retain the... (3 Replies)
Discussion started by: easwam
3 Replies

8. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

9. UNIX for Dummies Questions & Answers

cat to a file but retain header

Hi, Is there a way to write to a txt file each day but retain the header on the file? I'm cat'ing 5 files into one .txt file each day but I want the new data to be written after the first 2 lines which are: Progname Size Date Owner ---------------------------- Basically I want my new... (4 Replies)
Discussion started by: Grueben
4 Replies

10. Programming

[Solved] Removing duplicates from the file and saving as new file

Dear All I have 200 data files and each files has many duplicates. I am looking for the automated awk script such that it checks and removes the duplicates from the each file and saving them as new files for all 200 files in the respective folder. For example my data looks like this.. ... (12 Replies)
Discussion started by: bala06
12 Replies
chmod(1)							   User Commands							  chmod(1)

NAME
chmod - change the permissions mode of a file SYNOPSIS
chmod [-fR] absolute-mode file... chmod [-fR] symbolic-mode-list file... DESCRIPTION
The chmod utility changes or assigns the mode of a file. The mode of a file specifies its permissions and other attributes. The mode may be absolute or symbolic. Absolute mode An absolute mode specification has the following format: chmod [options] absolute-mode file . . . where absolute-mode is specified using octal numbers nnnn defined as follows: n a number from 0 to 7. An absolute mode is constructed from the OR of any of the following modes: 4000 Set user ID on execution. 20#0 Set group ID on execution if # is 7, 5, 3, or 1. Enable mandatory locking if # is 6, 4, 2, or 0. For directories, files are created with BSD semantics for propagation of the group ID. With this option, files and subdi- rectories created in the directory inherit the group ID of the directory, rather than of the current process. For direc- tories, the set-gid bit may only be set or cleared by using symbolic mode. 1000 Turn on sticky bit. See chmod(2). 0400 Allow read by owner. 0200 Allow write by owner. 0100 Allow execute (search in directory) by owner. 0700 Allow read, write, and execute (search) by owner. 0040 Allow read by group. 0020 Allow write by group. 0010 Allow execute (search in directory) by group. 0070 Allow read, write, and execute (search) by group. 0004 Allow read by others. 0002 Allow write by others. 0001 Allow execute (search in directory) by others. 0007 Allow read, write, and execute (search) by others. For directories, the setgid bit cannot be set (or cleared) in absolute mode; it must be set (or cleared) in symbolic mode using g+s (or g- s). Symbolic mode A symbolic mode specification has the following format: chmod [options] symbolic-mode-list file . . . where symbolic-mode-list is a comma-separated list (with no intervening whitespace) of symbolic mode expressions of the form: [who] operator [permissions] Operations are performed in the order given. Multiple permissions letters following a single operator cause the corresponding operations to be performed simultaneously. who zero or more of the characters u, g, o, and a specifying whose permissions are to be changed or assigned: u user's permissions g group's permissions o others' permissions a all permissions (user, group, and other) If who is omitted, it defaults to a, but the setting of the file mode creation mask (see umask in sh(1) or csh(1) for more information) is taken into account. When who is omitted, chmod will not override the restrictions of your user mask. operator either +, -, or =, signifying how permissions are to be changed: + Add permissions. If permissions is omitted, nothing is added. If who is omitted, add the file mode bits represented by permissions, except for the those with corresponding bits in the file mode creation mask. If who is present, add the file mode bits represented by the permissions. - Take away permissions. If permissions is omitted, do nothing. If who is omitted, clear the file mode bits represented by permissions, except for those with corresponding bits in the file mode creation mask. If who is present, clear the file mode bits represented by permissions. = Assign permissions absolutely. If who is omitted, clear all file mode bits; if who is present, clear the file mode bits represented by who. If permissions is omitted, do nothing else. If who is omitted, add the file mode bits represented by permissions, except for the those with corresponding bits in the file mode creation mask. If who is present, add the file mode bits represented by permissions. Unlike other symbolic operations, = has an absolute effect in that it resets all other bits represented by who. Omitting permissions is useful only with = to take away all permissions. permission any compatible combination of the following letters: l mandatory locking r read permission s user or group set-ID t sticky bit w write permission x execute permission X execute permission if the file is a directory or if there is execute permission for one of the other user classes u,g,o indicate that permission is to be taken from the current user, group or other mode respectively. Permissions to a file may vary depending on your user identification number (UID) or group identification number (GID). Permissions are described in three sequences each having three characters: User Group Other rwx rwx rwx This example (user, group, and others all have permission to read, write, and execute a given file) demonstrates two cate- gories for granting permissions: the access class and the permissions themselves. The letter s is only meaningful with u or g, and t only works with u. Mandatory file and record locking (l) refers to a file's ability to have its reading or writing permissions locked while a program is accessing that file. In a directory which has the set-group-ID bit set (reflected as either -----s--- or -----l--- in the output of 'ls -ld'), files and subdirectories are created with the group-ID of the parent directory--not that of current process. It is not possible to permit group execution and enable a file to be locked on execution at the same time. In addition, it is not possible to turn on the set-group-ID bit and enable a file to be locked on execution at the same time. The following examples, therefore, are invalid and elicit error messages: chmod g+x,+l file chmod g+s,+l file Only the owner of a file or directory (or the super-user) may change that file's or directory's mode. Only the super-user may set the sticky bit on a non-directory file. If you are not super-user, chmod will mask the sticky-bit but will not return an error. In order to turn on a file's set-group-ID bit, your own group ID must correspond to the file's and group execution must be set. OPTIONS
The following options are supported: -f Force. chmod will not complain if it fails to change the mode of a file. -R Recursively descends through directory arguments, setting the mode for each file as described above. When symbolic links are encountered, the mode of the target file is changed, but no recursion takes place. OPERANDS
The following operands are supported: absolute-mode Represents the change to be made to the file mode bits of each file named by one of the file operands. See Absolute Mode symbolic-mode-liand Symbolic Mode above in the DESCRIPTION section for more information. file A path name of a file whose file mode bits are to be modified. USAGE
See largefile(5) for the description of the behavior of chmod when encountering files greater than or equal to 2 Gbyte ( 2**31 bytes). EXAMPLES
Example 1: Denying execute permission to everyone example% chmod a-x file Example 2: Allowing only read permission to everyone example% chmod 444 file Example 3: Making a file readable and writable by the group and others example% chmod go+rw file example% chmod 066 file Example 4: Causing a file to be locked during access example% chmod +l file Example 5: Allowing everyone to read, write, and execute the file and turn on the set group-ID example% chmod a=rwx,g+s file example% chmod 2777 file ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of chmod: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
getfacl(1), ls(1), setfacl(1), chmod(2), attributes(5), environ(5), largefile(5), standards(5) NOTES
Absolute changes do not work for the set-group-ID bit of a directory. You must use g+s or g-s. chmod permits you to produce useless modes so long as they are not illegal (for instance, making a text file executable). chmod does not check the file type to see if mandatory locking is meaningful. If the filesystem is mounted with the nosuid option, setuid execution is not allowed. If you use chmod to change the file group owner permissions on a file with ACL entries, both the file group owner permissions and the ACL mask are changed to the new permissions. Be aware that the new ACL mask permissions may change the effective permissions for additional users and groups who have ACL entries on the file. Use the getfacl(1) command to make sure the appropriate permissions are set for all ACL entries. SunOS 5.10 4 Dec 2000 chmod(1)
All times are GMT -4. The time now is 05:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy