- If you want to create a logfile called "myapp_log.11.Mar.2007″
- If you want to write to a logfile with "myapp: 11 Mar 2007 22:14:44: Something Happened"
Tuesday, March 17, 2015
Solaris/Shell-scripts: Timestamps for Log Files
Solaris: The RSTCHOWN parameter & Changing File Ownership
By default, in Solaris, the owner of the file cannot use the chown command to change the owner of the file or directory. There is also restriction in using chgrp command. The owner can only use chgrp command to change the group of the file to a group, which the owner belongs to.
However, this behavior can be changed by modifying /etc/system file by adding the following line:
set rstchown=0
You need to reboot your system after this change. Only the root can arbitrarily change ownership of the file whether or not this option is in effect.
Let's check the difference in system's behavior in following examples. We have the user account nameduser1 which is member of groups admin and dba. With default behavior when user1 is trying to change owner of the data.log file to user2 he gets the following message
$ chown user2 data.log
chown: data.log: Not owner
$ ls -l
total 12
-rw-rw-r-- 1 user1 admin 5345 May 11 05:53 data.log
However, user1 can change group of the data.log file to dba, because that is one of the two groups which he is a member of. But when user1 tries to change group of the data.log file to the manager his attempt will fail.
$ chgrp dba data.log
$ ls -l
total 12
-rw-rw-r-- 1 user1 dba 5345 May 11 05:53 data.log
$ chgrp manager data.log
chgrp: data.log: Not owner
Now, after the /etc/system file modification, user1 is free to change owner or group of his data.log file.
$ chown user2 data.log
$ ls -l
total 12
-rw-rw-r-- 1 user2 admin 5345 May 11 05:53 data.log
$ chgrp manager data.log
$ ls -l
total 12
-rw-rw-r-- 1 user1 manager 5345 May 11 05:53 data.log
There is possibility to change rstchown parameter on the fly without reboot using adb (mdb). This change will not persist across reboot though.
# adb -w -k /dev/ksyms /dev/mem
physmem 1f425
rstchown/D
rstchown:
rstchown: 1
rstchown/W 0
rstchown: 0x1 = 0x0
rstchown/D
rstchown:
rstchown: 0
You need to provide the name of the parameter you want to change together with valid option. In example above we printed current value assigned to rstchown by using /D and then we assigned new value by /W 0.
Solaris 11: Activate FASTREBOOT to significantly reduce boot time
The Fast Reboot feature of Oracle Solaris 11 is supported on both SPARC and x86 platforms. The Fast Reboot feature implements an in-kernel boot loader that loads the kernel into memory and then switches to that kernel, so that the reboot process occurs within seconds.
For x86 systems:
Fast reboot, bypassing firmware and boot loader. The new kernel will be loaded into memory by the running kernel, and control will be transferred to the newly loaded kernel. If disk or kernel arguments are specified, they must be specified before other boot arguments.
For SPARC systems:
Speeds up rebooting by skipping some POST tests.
The Fast Reboot feature is controlled by SMF and implemented through a boot configuration service, svc:/system/boot-config. The boot-config service provides a means for setting or changing the default boot parameters.
The fastreboot_default property of the boot-config service enables an automatic fast reboot of the system when either the reboot or the init 6 command is used. When the config/fastreboot_default property is set to true, the system automatically performs a fast reboot, without the need to use the reboot -f command. By default, this property's value is set to true on an x86 based system and false on a SPARC based system.
The svc:/system/boot-config:default service consists of the following properties:
For example, to disable the default behavior of the fastreboot_onpanic property on an x86 based system, you would set the property's value to false, as shown here:
The following example shows how to make a fast reboot the default behavior on a SPARC based system by setting the boot-config SMF service property to true.
To reboot a system that has the Fast Reboot feature enabled, without reconfiguring the boot-config service to disable the feature, use the -p option with the reboot command, as shown here:
Solaris: how to edit/vi huge files (GBs)
Every now and then you end up with task to read or edit file that is huge. By huge I mean the size of the file at least 1GB, more likely several GBs.
You usually notice huge file by the following message when you try to open it using vi editor:
The default directory /var/tmp for the vi editing buffer needs space equal to roughly twice the size of the file with which you are working, because vi uses extra lines for buffer manipulation.
This is how you choose another directory for vi's editing buffer:
You can replace /tmp with any other directory containing enough space as a editing buffer. The filename is the name of your large file.
In case you just need to read file and do not plan to edit it, you can use one of the commands that use fewer resources like less, head or tail.
Other option would be to split the file either size-wise or line-wise.
Each of new files will have 10000 lines. Or you can try
which will create 250MB chunks out of the original file.
If you prefer to use vim over vi, you might try to press Ctrl-C when loading your file. Vim tries to read in the whole file initially to do things like syntax highlighting, number of lines in file and so on. Ctrl-C will cancel this and will only load what's needed to display on your screen.
Solaris 10: Unable to login into NonGlobal Zones (NGZ) after Patching
[ Aug 27 09:36:58 Enabled. ]
[ Aug 27 09:37:01 Executing start method ("/lib/svc/method/sysidtool-net") ]
/etc/.UNCONFIGURED not found. System already configured, /lib/svc/method/sysidtool-net exiting.
[ Aug 27 09:37:01 Method "start" exited with status 0 ]
[ Aug 27 14:58:06 Enabled. ]
[ Aug 27 14:58:12 Executing start method ("/lib/svc/method/sysidtool-net") ]
ifconfig: status: SIOCGLIFFLAGS: fjgi0: no such interface
ifconfig: setifflags: SIOCGLIFFLAGS: fjgi0: no such interface
ifconfig: status: SIOCGLIFFLAGS: fjgi7: no such interface
ifconfig: setifflags: SIOCGLIFFLAGS: fjgi7: no such interface
Terminated
Solaris 10: How to give Special Privileges to specific Zones
- Default Privileges- which are assigned to every zone during the installation
Allows a process to change a file's group ID to one other than the process' effective group ID or one of the process' supplemental group IDs.
- Optional Privileges- which we have to assign manually, using the limitpriv option
limitpriv:
global-zone# zonecfg -z myzone set limitpriv="default,sys_time"
global-zone# zoneadm -z myzone reboot
- Prohibited Privileges - which currently not supported to assign
contract_event
Allows a process to request critical events without limitation.
Allows a process to request reliable delivery of all events on
any event queue.
contract_observer
Allows a process to observe contract events generated by
contracts created and owned by users other than the process's
effective user ID.
Allows a process to open contract event endpoints belonging to
contracts created and owned by users other than the process's
effective user ID.
file_chown
Allows a process to change a file's owner user ID.
Allows a process to change a file's group ID to one other than
the process' effective group ID or one of the process'
supplemental group IDs.
-------------------------- SNIP ---------------------------------
| Privilege | Status | Notes |
| cpc_cpu | Optional | Access to certain cpc(3CPC) counters |
| dtrace_proc | Optional | fasttrap and pid providers; plockstat(1M) |
| dtrace_user | Optional | profile and syscall providers |
| graphics_access | Optional | ioctl(2) access to agpgart_io(7I) |
| graphics_map | Optional | mmap(2) access to agpgart_io(7I) |
| net_rawaccess | Optional in shared-IP zones. Default in exclusive-IP zones. | Raw PF_INET/PF_INET6 packet access |
| proc_clock_highres | Optional | Use of high resolution timers |
| proc_priocntl | Optional | Scheduling control; priocntl(1) |
| sys_ipc_config | Optional | Raising IPC message queue buffer size |
| sys_time | Optional | System time manipulation; xntp(1M) |
| dtrace_kernel | Prohibited | Currently unsupported |
| proc_zone | Prohibited | Currently unsupported |
| sys_config | Prohibited | Currently unsupported |
| sys_devices | Prohibited | Currently unsupported |
| sys_linkdir | Prohibited | Currently unsupported |
| sys_net_config | Prohibited | Currently unsupported |
| sys_res_config | Prohibited | Currently unsupported |
| sys_suser_compat | Prohibited | Currently unsupported |
| proc_exec | Required, Default | Used to start init(1M) |
| proc_fork | Required, Default | Used to start init(1M) |
| sys_mount | Required, Default | Needed to mount required file systems |
| sys_ip_config | Required, Default in exclusive-IP zones Prohibited in shared-IP zones | Required to boot zone and initialize IP networking in exclusive-IP zone |
| contract_event | Default | Used by contract file system |
| contract_observer | Default | Contract observation regardless of UID |
| file_chown | Default | File ownership changes |
| file_chown_self | Default | Owner/group changes for own files |
| file_dac_execute | Default | Execute access regardless of mode/ACL |
| file_dac_read | Default | Read access regardless of mode/ACL |
| file_dac_search | Default | Search access regardless of mode/ACL |
| file_dac_write | Default | Write access regardless of mode/ACL |
| file_link_any | Default | Link access regardless of owner |
| file_owner | Default | Other access regardless of owner |
| file_setid | Default | Permission changes for setid, setgid, setuid files |
| ipc_dac_read | Default | IPC read access regardless of mode |
| ipc_dac_owner | Default | IPC write access regardless of mode |
| ipc_owner | Default | IPC other access regardless of mode |
| net_icmpaccess | Default | ICMP packet access: ping(1M) |
| net_privaddr | Default | Binding to privileged ports |
| proc_audit | Default | Generation of audit records |
| proc_chroot | Default | Changing of root directory |
| proc_info | Default | Process examination |
| proc_lock_memory | Default | Locking memory; shmctl(2)and mlock(3C) If this privilege is assigned to a non-global zone by the system administrator, consider also setting the zone.max-locked-memory resource control to prevent the zone from locking all memory. |
| proc_owner | Default | Process control regardless of owner |
| proc_session | Default | Process control regardless of session |
| proc_setid | Default | Setting of user/group IDs at will |
| proc_taskid | Default | Assigning of task IDs to caller |
| sys_acct | Default | Management of accounting |
| sys_admin | Default | Simple system administration tasks |
| sys_audit | Default | Management of auditing |
| sys_nfs | Default | NFS client support |
| sys_resource | Default | Resource limit manipulation |
Monday, March 16, 2015
Solaris: Interrupts and Priorities
To get details of Interrupts on a system; use "ptime" command
Example:
- root# /usr/bin/ptime /usr/share/lib/dict/words
- Observe the time taken (Real, User & System).
- Repeat the command again. This time the command should be reading the file contents from memory cache. So the "Real time" should be shorter.
- Execute the command again, but use the mouse button to drag the window around the screen while the command is executing.
- Observe the time taken (Real, User & System).
